character string

Python Strings are written in a variety of ways , Mainly :Single quotes( A pair of single quotation marks ),Double quotes( A pair of double quotation marks ) also Triple
quoted( Three quotation marks referencing multiline text ) Three forms .
>>> print("let's go") let's go >>> cyc=""" i love you i love you """ >>>
print(cyc) i love you i love you >>>
Escape character

>>> print("a\n\d\t\c") a \d \c >>> print("a\\n\d\\t\c") a\n\d\t\c >>>
Addition and multiplication of strings
>>> 5+5 10 >>> '5'+'5' '55' >>> '5'*10 '5555555555'

random number random

random.randint(a,b) generate a reach b Random number between

type function

View the type of data :type()

input function

Whatever you enter , Data types are all string types

So the type conversion function is used here

int(x) take x Convert to integer

float(x) take x Convert to floating point number

Formatted output of variables

# Define string variables name name = " Xiao Ming " print(" My name is %s." % name) #
Defining integer variables student_no, Output my student number is 000001 student_no = 1 print(" My student number is %06d" % student_no) #
Define decimal price,weight,money, Output Apple unit price 9.12/ Jin , # Purchased 5.00 Jin , To be paid 45.60 element price = 9.12 weight
= 5.00 money = price * weight print(" Apple unit price %.2f element / Jin , Purchased %.2f Jin , To be paid %.2f" % (price,
weight, money)) # Define a decimal scale , Output data scale is 2.50% scale = 0.25 print(" Data scale is %.2f%%" %
(scale*10))
Identifiers and keywords

Identifier consists of letters , number , Underline composition , Cannot start with a number , Can only be letters or underscores .

if.....else function

Logical operation

elif function

if Nesting of ,

Random function ,

while loop

Assignment Operators

break and continue

break: When a condition is met , Exit loop , Do not execute the code repeated later

continue: When a condition is met , Do not execute the code repeated later
# break Demo of , # Output only 0,1,2 # i = 0 # while i < 10: # if i == 3: # #
, Meet the conditions , Exit loop , Do not execute the code repeated later # break # print(i) # i += 1 # # print("over") #
continue Demo of , # except 3 Output everything else i = 0 while i < 10: if i == 3: #
use continue before , Need to confirm whether the count is modified , Prevent entry into dead cycle i += 1 continue print(i) i += 1
while loop nesting
# Print small stars , output 5 that 's ok *, The quantity of each line decreases in turn # print Function wraps lines on the console after output ,print(a,end="") No line breaks allowed # i = 1 #
while i <= 5: # print("* " * i, end="") # i += 1 # Assume no multiplication row = 1 while row
<= 5: # Add column loop , Responsible for the display of each column col = 1 while col <= row: print("*", end="") col += 1 #
print(" Section %d that 's ok " % row) # Line feed after one line of star output is completed print("") row += 1
Escape character

 

Technology
©2019-2020 Toolsou All rights reserved,
Solve in servlet The Chinese output in is a question mark C String function and character function in language MySQL management 35 A small coup optimization Java performance —— Concise article Seven sorting algorithms (java code ) use Ansible Batch deployment SSH Password free login to remote host according to excel generate create Build table SQL sentence Spring Source code series ( sixteen )Spring merge BeanDefinition Principle of Virtual machine installation Linux course What are the common exception classes ?