[Introduction to python---Basic knowledge]

This content is all personal notes, you can take a look, if you think it is good, give it a like and encourage newbies.

Article directory


1. Python’s job tree?

 

 

2. What is python?

Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. It is one of the mainstream programming languages ​​today.

1.Python syntax basics

The code is as follows (example):

#单行注释
city='beijing'
loction='北京市朝阳区姚家园'
print(city)
print(loction)
#多行注释
Loct='''
姓名:小白
年龄:20
联系方式:xxxxxxxxxx'''
print(loct)

#将int转换为float
print(float(10))
print('int转换为float:',float(10))
print(int('3'))#将str转换为int、float
print('str转换为int:',int('3'))#int内只能为整数,且不能带有字母
print('str转换为float:',float('3.14')#同上

2.eval function

The code is as follows (example):

#name中不加eval,因为输入内容为字符串
s='3.14+5'
print(s,type(s))
x=eval(s)#eval函数是去掉字符串之后进行运算
print(x,type(x))
#eval常与input函数连用,用来获取用户输入的数值
age=eval(input('你的年龄是:'))#eval将字符串转换为int类型,相当于int(age)
print(age,type(age))
height=eval(input('你的身高是:'))#eval将字符串转换为float类型,相当于float(height)
print(height,type(height))
#hello='我爱python!'
#eval的错误使用
print(eval('hello'))#结果执行print(hello)


3. Small exercises after class

        1. Enter four digits at will and calculate the tens, hundreds and thousands of digits in sequence.

as follows:

num = eval(input('请输入一个四位数的数字:'))
a = num % 10
b = num // 10 % 10
c = num // 100 % 10
d = num // 1000
print('个位数字是:', a)
print('十位数字是:', b)
print('百位数字是:', c)
print('千位数字是:', d)

Summarize


The above is what I will talk about today. This article only briefly introduces the career and basic learning of python. I hope you will show your talents in the field of python in the future.

Guess you like

Origin blog.csdn.net/qq_72356432/article/details/125742469
Recommended