当前位置:网站首页>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()
边栏推荐
猜你喜欢
redis 集群模式原理
Liunx prohibit Ping explain the different usage of traceroute
[cloud native | kubernetes] actual battle of ingress case (13)
[yolov5.yaml parsing]
[configuration method of win11 multi-user simultaneous login remote desktop]
自动化测试生命周期
How to clear floating?
Thoughts and suggestions on the construction of intelligent management and control system platform for safe production in petrochemical enterprises
Matlab imoverlay function (burn binary mask into two-dimensional image)
【上采样方式-OpenCV插值】
随机推荐
Mmclassification training custom data
【云原生 | Kubernetes篇】Ingress案例实战(十三)
Redis master-slave mode
abap查表程序
【pytorch 修改预训练模型:实测加载预训练模型与模型随机初始化差别不大】
《看完就懂系列》15个方法教你玩转字符串
Programmers are involved and maintain industry competitiveness
leetcode:1200. Minimum absolute difference
Pytorch weight decay and dropout
【Win11 多用户同时登录远程桌面配置方法】
Halcon template matching actual code (I)
redis主从中的Master自动选举之Sentinel哨兵机制
2022年国内云管平台厂商哪家好?为什么?
How to make your products as expensive as possible
多表操作-子查询
1. Laravel creation project of PHP
What is the difference between canvas and SVG?
The most comprehensive new database in the whole network, multidimensional table platform inventory note, flowus, airtable, seatable, Vig table Vika, flying Book Multidimensional table, heipayun, Zhix
12.(地图数据篇)cesium城市建筑物贴图
【 YOLOv3中Loss部分计算】