In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
Each language has a variety of data types. This is like in real life, we need to use numbers when counting, decimals when expressing amount, weight, distance, etc., words in daily conversation, and so on. In computer language, in order to express different situations, various data types are also needed.
In Python there are mainly numeric types (int, float), string types, Boolean types and null values.
Integer int
In Python, integers are used to represent integers, positive or negative numbers, with no decimal point. 10 and 10.0 are two data types.
Floating point number float
Floating point numbers are our common numbers with decimal points. It is called a floating point because the position of the decimal point is not fixed, that is, floating.
For example, 10.01 can be written as 1.001 10 ^ 1 or 0.1001 10 ^ 2.
String str
Strings are one of the most commonly used data types, and strings are wrapped in quotation marks. In Python, quotation marks can be double or single quotation marks. But you can't mix it.
You can also mark multiline strings with three pairs of quotation marks (either single or double).
> char = 'nemo' # single quotation marks > char2 = "python" # double quotes > char3 =' python "# mixed single and double quotes, syntax error > char4 = 'this's a pig' # syntax error, you can replace the outer quotation marks with double quotes, or use escape characters > > char5 =' this\'s a pig'
There is also a lot of string manipulation in Python, which will be explained in more detail in subsequent tutorials.
Boolean bool
Boolean type, there are only two values, that is, what we usually call true and false, wrong and right, yes and no.
In computer language, Boolean value is usually used to indicate whether the condition is true, True if the condition is true and False if it is not true.
> 3 > 1True > 0
< 5False>> > 5 = = '5'False null value None
Null None is a special data type in Python, and it is not strictly a data type either. A null value is used to indicate that there is nothing, an empty string is not empty, an empty string is a string, and a null value is nothing. Expressed as null in other languages or databases.
It is common in functions, when the function does not define a return value, the default return is None.
Common functions for judging data types
In Python, there are two main functions for determining data types, type () and isinstance ().
The type () function is used to view the type of data:
> type (5) > type (5.0) > type ('5')
Isinstance () is used to determine the type of data, which matches the returned True and does not conform to the returned False:
> isinstance (5, int) # isinstance requires two parameters, the first is the value, and the second is the type True > isinstance ('5percent, int) False > isinstance (' 5percent, str) True > isinstance (True, int) True > isinstance (True, bool) True
There is a phenomenon that isinstance (True, int) is also consistent. We said above that True is Boolean, but why is int consistent?
In fact, Boolean is a kind of int, with values of only 0 and 1.
> True = = 1True > False = = 0True data types convert different data types can be converted to each other. If you want to convert to an integer type, you can use the int () function, if you switch to a floating point type, you can use the float () function, and if you convert to a string type, you can use the str () function.
Target type function intint () strstr () floatfolat () > > int ('15a') 15 > int (' 15a') # error, string to int, must be all decimal digits ValueError: invalid literal for int () with base 10: '15a' > > int (' 1.1') # report error, it doesn't seem to work even if floating point But this can be converted to floating point ValueError with float: invalid literal for int () with base 10: '1.1' > > float ('1.1') 1.1 > float ('11') 11.0 > str (100)' 100'
You can try the rest of the conversion on your own.
In Python, any data type is an object! Of course, it's more than that, everything you see in Python is object. But this sentence does not need to be understood now, just remember it first.
Thinking about this conclusion
5 = = 5.0, what is the result? Why?
5 is 5.0.What is the result? Why?
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.