Variables and types
a=1 #Variable a is an integer
t007='T007” #Variable t007 is a string
Python some identifiers with special functions, these are the so-called keywords
The keyword is already used by python, so developers are not allowed to define the identifier with the same name as the keyword.
>>> import keyword #First introduce the keyword package
>>> keyword.kwlist #View keywords
and as assert breakclasscontinue def del
elif else except exec finallyforfrom global
ifinimport is lambda not or pass
print raise returntrywhilewithyield
# Normal output
a=10print("This is the variable",a)
# Formatted output
age=20
name="Xiao Zhang"print("His age is%d years old"%age)print("his name is%s, nationality is%s"%(name,"China"))
operation result
print("aaa","bbb","ccc")print("www","baidu","com",sep=".")
result:
print("hello",end="") #No line break
print("world",end="\t") #A tab before the next output
print("python",end="\n") #Wrap
print("end")
result:
password =input("Please enter password:") #keyboard input
print("The password you just entered is:",password)print("The types of numbers entered by the keyboard are:",type(password)) #The keyboard input is a string type
password_2 =int(password) #Cast to int type
print("The type after coercion is:",type(password_2))
result:
Recommended Posts