当前位置:网站首页>II. Data type
II. Data type
2022-07-05 12:08:00 【Banyuanjun 578】
One Basic types of variables
One Immutable
️ A single element in a variable cannot be modified , increase , Delete
1 character string - str - string
2 integer - int - integer
3 floating-point - float
4 Tuples - tuple
(1, 2, 3, " university ")
Two Variable form
1 Dictionaries - dict - dictionary
{'name' : 'Nice', 'age' : 35}
2 list - list - dictionary
[1, 2, 3, 3.14, ' university ']
3、 ... and Common commands
len() Determine the length of the string
type() Judge the type of variable
id() Address corresponding to output variable
Two character string
Python Middle single quotation marks and double quotation marks are used exactly the same
Use three quotation marks to specify a multiline string
word = 'String' sentence = "This is sentence" paragraph = """This is a paragraph that can consist of multiple lines"""
Escape character : The backslash
# ** Be careful ** # 1. Escape symbols cannot appear at the end of a string
Backslash can be used to escape , Use r You can keep the backslash from escaping . Such as :r"this is a line with \n" be \n Will be displayed , They don't execute
Concatenate strings literally . Such as :"this" "is" "string" Will be automatically converted to this is string
String can be used + Operator Connect together , use * Operator repeat
Python There are two ways to index strings in , From left to right 0 Start , From right to left -1 Start
Python String in cannot be changed
Python No separate character type , One character is the length of 1 String
Syntax format of string interception : Variable [ Header subscript : Tail subscript : step ]
str = '123456789' print(str) print(str[0:-1]) # Output all characters from the first to the last print(str[0]) # Output the first character print(str[2:5]) print(str[2:]) # Output all characters after the third start print(str[1:5:2]) # Running results :24 print(str * 2) # Output string twice print(str + 'GAME OVER!') # Connection string print(r'GAME OVER!\n') # Use r You can keep the backslash from escaping
3、 ... and “ The amount ” All kinds of changes
One example
# Other data types -> character string
my_age = 18
my_new_age = str(my_age)
# Other data types -> Integers
room_number = "520"
room_new_number = int(room_number)
# Other data types -> Floating point numbers
ticket_price = "3.5"
ticket_new_price = float(ticket_price)
Two matters needing attention
Floating point to integer will eliminate the decimal part
A non integer number in the string cannot be converted to an integer
Non integer in string cannot be converted to floating point
String or integer to floating point number , There is one more decimal after the integer
Four Math library math The common method of
One Python Built in mathematical functions
The absolute value abs()
minimum value min()
Maximum max()
Two Python math Library math functions
️ Note that you need to import import math
Take the whole number up ceil()
Take the whole number down floor()
Square root sqrt()
边栏推荐
- Hash tag usage in redis cluster
- 程序员内卷和保持行业竞争力
- 简单解决redis cluster中从节点读取不了数据(error) MOVED
- Programmers are involved and maintain industry competitiveness
- 一次生产环境redis内存占用居高不下问题排查
- 互联网公司实习岗位选择与简易版职业发展规划
- 16 channel water lamp experiment based on Proteus (assembly language)
- Video networkstate property
- The solution of outputting 64 bits from printf format%lld of cross platform (32bit and 64bit)
- Proof of the thinking of Hanoi Tower problem
猜你喜欢
随机推荐
无线WIFI学习型8路发射遥控模块
一次生产环境redis内存占用居高不下问题排查
程序员内卷和保持行业竞争力
pytorch-权重衰退(weight decay)和丢弃法(dropout)
What is the difference between canvas and SVG?
【L1、L2、smooth L1三类损失函数】
Reinforcement learning - learning notes 3 | strategic learning
Multi table operation - sub query
Riddle 1
一类恒等式的应用(范德蒙德卷积与超几何函数)
12. (map data) cesium city building map
投资理财适合女生吗?女生可以买哪些理财产品?
Halcon template matching actual code (I)
Is investment and finance suitable for girls? What financial products can girls buy?
15 methods in "understand series after reading" teach you to play with strings
Matlab label2idx function (convert the label matrix into a cell array with linear index)
Principle of redis cluster mode
yolov5目标检测神经网络——损失函数计算原理
View all processes of multiple machines
想问问,如何选择券商?在线开户是很安全么?