[Introduction to Python - Basic Learning]

1. How to use
print print(ord('北'))#The encoding of the word '北'
print('\u5317')
print('Beijing welcomes you')
print('Beijing welcomes you'+'2022')
print (1,2,3,4,sep='!')
print('Beijing',end='!')
print('We welcome you!')
#Use print to create a file
py=open('note.txt' ,'w')
print('Welcome to Beijing',file=py)
py.close()

 

2. How to use input
name=input('Your name is:')
print('Your name is:'+name)

num=int(input('Your lucky number is:'))
#print('Your lucky number is:'+num) At this time, '+' is used as an operator, so the error
print('Your lucky number is :',num)


3. Check the keyword
import keyword
print(keyword.kwlist)

4. Create a complete variable and assign the value
luck_number=8
my_name='Xiao Ming'
print(my_name,'The lucky number is:',luck_number)
print('The data type of luck_number is:',type(luck_number))

5. Binary, octal, hexadecimal
num=789
num1=0b1010101
num2=0o776
num3=0x78ABF
print(num) print
(num1)
print(num2)
print(num3)

おすすめ

転載: blog.csdn.net/qq_72356432/article/details/125696263