In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains the "Python data types and common methods are", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in-depth, together to study and learn "Python data types and common methods are what" it!
As soon as introduced
We learn variables so that computers can remember a certain state of things like human beings, and the values of variables are used to store the state of things, and it is obvious that the states of things are divided into different types (such as people's age, height, position, salary, etc.), so the value of variables should also have different types, such as
Salary = 3.1 # use floating point to record salary age = 18 # use integer to record age name = 'lili' # use string type to record person name two numeric type 2.1 int integer 2.1.1 function
It is used to record the integer related states such as age, year of birth, number of students, etc.
2.1.2 define age=18birthday=1990student_count=482.2 float floating point 2.2.1 action
Used to record the decimal-related status of a person's height, weight, salary, etc.
2.2.2 define the use of height=172.3weight=103.5salary=15000.892.3 numeric types
1. Mathematical operation
> a = 1 > > b = 3 > > c = a + b > > c4
2. Compare the size
> x = 10 > y = 11 > x > yFalse three string types str3.1 action
Used to record the descriptive state of a person's name, home address, gender, etc.
3.2Definitions name = 'Tony'address =' Shanghai Pudong New area 'sex =' male'
Using single quotation marks, double quotation marks, and multiple quotation marks, you can define a string, which is essentially indistinguishable, but
# 1. Need to consider the matching problem of nesting quotation marks msg = "My name is Tony, iComm 18 years old!" # there are single quotation marks in the inner layer and double quotation marks in the outer layer. Multiple quotation marks can be used to write multi-line strings msg =''. There are only two kinds of people in the world. For example, when you get a bunch of grapes, one kind of person chooses the best to eat first, while the other saves the best for last. As a rule, the first kind of person should be optimistic, because every one he eats is the best of the leftover grapes; the second should be pessimistic, because every one he eats is the worst of the leftover grapes. However, the fact is counterproductive, because the second kind of people still have hope, and the first kind of people only have memories. Numbers can be used for addition, subtraction, multiplication and division, and strings can also be added, but only "addition" and "multiplication" can be carried out. > name = 'tony' > age =' 18'> > name + age # addition is actually a simple string concatenation 'tony18' > > name * 5 # multiplication is equivalent to adding the string five times' tonytonytonytonytony' four-list list4.1 function.
If we need to record the names of multiple students with a single variable, it is impossible to do so with a numeric type, and the string type can indeed be recorded, such as
Stu_names=' Zhang San Li Si Wang Wu', but the purpose of saving is to get it. At this time, it is very troublesome to take out the name of the second student, and the list type is specially used to record the values of multiple same attributes (such as the names of multiple students in a class, multiple hobbies of the same person, etc.), and access is very convenient.
4.2 definition > > stu_names= ['Zhang San','Li Si', 'Wang Wu'] 4.3 use # 1. The list type corresponds to the value by index, and the index represents the position of the data. Count from 0 > > stu_names= ['Zhang San','Li Si', 'Wang Wu'] > stu_names [0] 'Zhang San' > > stu_names [1]'Li Si'> stu_names [2] 'Wang Wu' # 2, the list can be nested Nesting values are as follows > students_info= [['jason',18, [' DBJ','xy']], ['jason',18, [' play','sleep']] > students_info [0] [2] [0] # take out the first hobby of the first student, 'DBJ' five dictionary dict5.1 function.
If we need to record multiple values with one variable, but multiple values are of different attributes, such as a person's name, age, and height, they can be stored in a list, but the list is indexed to the corresponding value, and the index cannot clearly express the meaning of the value. Dictionary types are used to store data in key:value form, in which key can have a descriptive function for value.
5.2Definitions > person_info= {'name':'tony','age':18,'height':185.3} 5.3 use # 1, dictionary types use key to correspond to values, and key can have descriptive functions for values Usually string type > person_info= {'name':'tony','age':18,'height':185.3} > person_info [' name'] 'tony' > person_info [' age'] 18 > person_info ['height'] 185.class2. Dictionaries can be nested Nesting values are as follows > students= [. {'name':'tony','age':38,'hobbies': [' play','sleep']},. {'name':'jack','age':18,'hobbies': [' read','sleep']},. {'name':'rose','age':58,'hobbies': [' music','read','sleep']} Students [1] ['hobbies'] [1] # take the second student's second hobby,' sleep' six Boolean bool6.1.
It is used to record the true and false states.
6.2Definitions > is_ok = True > is_ok = False6.3 usage
It is usually used as a condition of judgment, which we will use in if judgment.
Thank you for your reading, the above is the content of "Python data types and common methods". After the study of this article, I believe you have a deeper understanding of what the Python data types and common methods are, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.