当前位置:网站首页>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()
边栏推荐
- codeforces每日5题(均1700)-第五天
- The solution of outputting 64 bits from printf format%lld of cross platform (32bit and 64bit)
- 一类恒等式的应用(范德蒙德卷积与超几何函数)
- Yolov 5 Target Detection Neural Network - Loss Function Calculation Principle
- 全网最全的新型数据库、多维表格平台盘点 Notion、FlowUs、Airtable、SeaTable、维格表 Vika、飞书多维表格、黑帕云、织信 Informat、语雀
- How to protect user privacy without password authentication?
- Codeforces Round #804 (Div. 2)
- 13. (map data) conversion between Baidu coordinate (bd09), national survey of China coordinate (Mars coordinate, gcj02), and WGS84 coordinate system
- 调查显示传统数据安全工具在60%情况下无法抵御勒索软件攻击
- 1.php的laravel创建项目
猜你喜欢

查看rancher中debug端口信息,并做IDEA Remote Jvm Debug

splunk配置163邮箱告警

Splunk configuration 163 mailbox alarm

Course design of compilation principle --- formula calculator (a simple calculator with interface developed based on QT)

Seven ways to achieve vertical centering

pytorch-多层感知机MLP

Redirection of redis cluster

redis主从模式

pytorch-softmax回归
调查显示传统数据安全工具在60%情况下无法抵御勒索软件攻击
随机推荐
《看完就懂系列》15个方法教你玩转字符串
Redis集群的重定向
Thoughts and suggestions on the construction of intelligent management and control system platform for safe production in petrochemical enterprises
yolov5目标检测神经网络——损失函数计算原理
Video networkState 属性
Pytorch linear regression
Want to ask, how to choose a securities firm? Is it safe to open an account online?
嵌入式软件架构设计-消息交互
View all processes of multiple machines
Codeworks 5 questions per day (1700 average) - day 5
Video networkstate property
Error modulenotfounderror: no module named 'cv2 aruco‘
What is the difference between canvas and SVG?
报错ModuleNotFoundError: No module named ‘cv2.aruco‘
Multi table operation - sub query
1个插件搞定网页中的广告
[untitled]
[configuration method of win11 multi-user simultaneous login remote desktop]
7月华清学习-1
mmclassification 训练自定义数据