>>> import keyword
>>> keyword.kwlist
# Single-line comments
''' many That's ok notes Interpretation of the '''
""" This is also Multiline comment """
\
total = one + \
two
;
import keyword;keyword.kwlist
import os # Import the entire module
from os import path # Import functions in the module
from os import path,system # Import multiple functions
from os import * # Import all functions
Number
,String
,List
,Tuple
,Set
,Dictionary
a = b = c = 1 # Multivariable assignment
a,b,c = 1,2,'run' # Multivariable assignment
del a # Delete reference
del a,b,c # To delete multiple
type(a) # View data type
isinstance(a,int) # Judge data type
int
,bool
,float
,complex
+
,-
,*
,/
,//
( integer ),%
( Remainder ),**
''' Multiple lines Text '''
""" It's also Multiple lines Text """
str = ' This is a \' Escape character '
str = ' Connecting characters ' + ' Use plus sign '
str = ' Asterisk for repeated characters ' * 3
str[1:2:2] # Character slices [ rise : stop : step ]
str = r' It can also be used. r Character escape \n'
[]
,()
a = [1,2,3,'a','b']
b = [4,'c']
a[0:2] # section
a * 2 # repeat
a + b # Connection list
a = {
'a','b',1,2} # How it was created 1
b = set('abc') # How it was created 2
a - b # Difference set
a | b # Combine
a & b # intersection
a ^ b # a and b Elements that don't exist at the same time ( Remove intersection )
a = {
} # How it was created 1
b['a'] = 1 # How it was created 2
c[1] = b # How it was created 3
d = dict(a=1,b=2) # How it was created 4
e = dict([('a',1),('b',2)]) # How it was created 5
print(b.keys())
print(b.values())
==
,!=
,>
,<
,>=
,<=
+=
,-=
,*=
,/=
,%=
,**=
,//=
and
,or
,not
in
,not in
is
,is not
abs
cel
exp
fabs
floor
log
log10
max
min
modf
pow
round
sqrt
name = 'dan'
'Hellow %s' % name
f'Hello {
name}'
a = 1
f'{
a+1}'
a = [1,2,'a']
a.append('b') # Additional tuple Elements in are not allowed to be modified
del a[2] # Delete
len(a) # length
'a' in a # Whether there is
a = {
'a','b','c'}
a.add('d')
a.update(x)
a.remove('d') # Element does not exist will report an error
a.discard('d') # Same as remove But there is no error
age = 18
if age > 18:
print('adult')
elif age > 14:
print('young man')
else:
print('kid')
counter = 1
sum = 0
while True:
sum += counter
if sum > 50:
break
count = 0
while count < 5:
count += 1
else:
print(' Greater than or equal to 5')
while True: print(' One line and infinite loop ')
for i in range(4):
print(i)
for i in range(4):
print(i)
else:
print(' The loop ends ')
a = list(range(4))
it = iter(a)
for x in it:
next(it)
a = ['a','b','c']
for x,y in enumerate(a):
print(' Subscript :%s' % x)
print(' value :%s' % y)
a = [1,2,3]
b = ['a','b','c']
for x,y in zip(a,b):
print(a,b)
a = {
'a':1,'b':2}
for k in a:
print('key:%s' % k)
print('item:%s' % a[k])
for k,v in a.items():
print('key:%s' % k)
print('item:%s' % v)
def hanshu():
pass
def hanshu(age=18):
print(age)
def hanshu(age,*info):
print(age)
print(info)
def hanshu(age,**info):
print(age)
print(info)
lambda Parameters : result
>>> sum = lambda x,y:x+y
>>> print(sum(1,2))
3
Exit function
def hanshu():
return
# return None
1. Which is True, Which is Fal
Catalog One 、 brief introduct
Preface Python Daily practice