1. Print

print('hello python') # hello python # n Newline CTRL + left click print to see the native API print("Wang", end=""# cancel print default newline print("Old zhang")
Copy the code

2. Operation

print(8 // 2) # 4
print(6 % 2)  # 0Modulo print (2支那3)  # 82Omega to the third x is equal to omega2
x += 2 # x = x + 2   4
x -= 2 # x = x - 2   2
x *= 2 # x = x * 2   4
x /= 2 # x = x / 2   2
x %= 2 # x = x % 2   0
x **= 2 # x = x ** 2   0The power of x//= 2 # x = x // 2 0 quotient
print(x)
Copy the code

3. Comments

# single-line comment""CTRL + Alt + L File formatting Code => reformat Code"""
Copy the code

4. The variable

Basic data typesNumber Bool Str List Tuple Dict SetPrint (isinstance('123'Print (type(float))'123'#)) <class 'str'>
print(type(12.6)) #"class 'float'>
print(type(55)) #"class 'int'>
print(type(True#)) <class 'bool'>
print(type([1, 2])) #"class 'list'>
print(type((1, 2))) #"class 'tuple'>
print(type({1.2#})) <class 'set'>
print(type({'1':2#})) <class 'dict'>
print(type(None#)) <class 'NoneType'>

NoneNo memory space ""IOInput and output:input  output
input(a.end=' ') without newline myName ="Zhang"The small hump is used to name the function MyName ="Zhang"The large hump is used for the class name my_name ="Zhang"The underscore is used for the variable name ="Wang"# assign the value of Lao Zhao to name. kwlist print(name)import keyword
print(keyword.kwlist)
myName = "Zhang"Shortcut key CTRL + D copy the selected line MyName ="Zhang"Capitalizing the first word of a class and capitalizing the next word my_name ="Zhang"# Underscore words are concatenated by _ for variables # number to string STR () num =12
print(type(num))
print(type(str(num)))  # '12'# number string to number float to integer int() str1 ="12"
print(int(str1))   # 12Float () num2 =12
print(float(num2)) # 12.0Integer to Boolean non-zero is true num3 =3Print (bool(num3)"Zhang"
age = 12
height = 1.75
print("My name is.",name) # My name is John # The first way to print % # Add the value of name to (%s string) (%d integer) (%f floating point) (%0.2f, two decimal digits) no space on it"My name is %s, my age % S, my height %s m"%(name,age,height) # My name is Zhang SAN my age12The height1.75M print ("My name is % S my age % F and my height %0.3f meters"%(name,age,height) # My name is Zhang SAN my age12.000000The height1.750{} format print("My name is {0} my age {1} and my height {2} m"Format (name,age,height)) # My name is Zhang SAN my age12The height1.75M print ("My name is {0} my age {1} and my height {2:.3f} m"Format (name,age,height)) # My name is Zhang SAN my age12The height1.750Enter # names = input("Please enter your name")2.2
# weight = float(input('number'))
# price = float(input('price'))
# print('total % 0.2 f'%(float(weight)*float(price)))
# print({' price: 2 f} '.format(weight*price))


print("Asd sasdasd ninini % % % % 0.3 faa"%(name,height))
print("Assad {1} ah true {0}".format(name,age)) # print(ord('A')) #65

print(chr(66)) #B
    
Copy the code