00 python basics

'' ' 
' '' 
Print ( ' the Hello world! ' ) 

'' ' 
Variables 
' '' 
# variables: 'tank', will produce a memory address in memory 
# variable name: the equivalent of a house number, for with variable bindings 
# =: used to bind variable value to a variable 
name = ' Tank ' 
Print (name)   # print Tank 

# variable name specification 
age_of_tank = 18 # Do not use the Chinese name 
name = Tank
 Print (name) # define three characteristic variable 
# ID: 
NAME1 = ' Tank ' 
NAME2 = 'tank1 ' #




python optimization mechanism (small integer pool) - as in a certain length is not exceeded as 
# a certain length, the same value python variable value stored in a unified memory in the same address 
Print (ID (NAME1))
 Print (ID (NAME2)) 

# type: determining the type of a variable 
str1 = ' Hello ' 
Print (type (str1)) 

# value 
str2 = ' Hello ' 
Print (str1 == str2) # returns TRUE 





'' ' 
constants: uppercase (can change but not change) 
'' ' 
SCHOOL = ' Hefei ' 
SCHOOL = ' HEFEI ' 
Print (SCHOOL) 

' ''
Users interact with a program  
    enter:
        input
    Output: 
        print () 
'' ' 

# allow the user to enter a user name 
name = input ( ' Please enter the name: ' ) 

# output user name 
print (name) 

# any data type in python3, enter in the input string are 
print (type (name)) 


'' ' 
Note: 
    single line: 
        # 
    multi-line: ' 
        '' 
'' ' 

' '' 
string format output 
'' ' 
# to replace gave 100% s 
str1 = ' I spent% s yuan, 0 left element ' % 100
 Print (str1)
 # the alternative to a 100% s, alternatively 50 to give D% 
str1 = ' I spent membered% s,% d remaining element' % ( ' One hundred ' , 50 )
 Print (str1)
 # error 
str1 = ' I spent yuan% s,% d remaining RMB ' % ( ' one hundred ' , ' 50 ' )
 Print (str1)

 

Guess you like

Origin www.cnblogs.com/urassya/p/11078895.html