In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "how to use int in Python". In daily operation, I believe many people have doubts about how to use int in Python. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to use int in Python". Next, please follow the editor to study!
There are several basic data types in Python:
Integer int
String str
Floating point number float
Set set
List list
Tuple tuple
Dictionary dict
Boolean type bool
Date date
The variable data types are: list (list), dict (dictionary), set (collection)
Immutable data types are: int (integer), float (floating point), str (string), bool (Boolean type), tuple (tuple)
What are mutable and immutable objects?
Immutable object: that is, the value in memory that the object points to cannot be changed. When changing a variable, because the value it refers to cannot be changed, it is equivalent to making a copy of the original value and then changing it, which opens up a new address, and the variable points to the new address.
Mutable object: this means that the value in memory that the object points to can be changed. After the variable (reference to be exact) is changed, the value it refers to changes directly, there is no copying behavior, and it does not open up a new address, what should be changed is the variable itself.
Int (Integer)
Often referred to as an integer or integer, a positive or negative integer without a decimal point
Create an integer: the equal sign is the variable name on the left and the value to be assigned on the right
A = 100 or b =-100
The operators before integer data type variables are: add (+), subtract (-), multiply (), divide (/), and power (*).
A = 1b = plus C1 = a + bprint (C1) # output: subtract c2 = b-aprint (c2) # output: multiply c3 = a * bprint (c3) # output: divide c4 = a / bprint (c4) # output: 0. The power-> is equal to the b power of a, c5 = a * * bprint (c5) # output: 1
Convert an integer type to a string
A = 100str_a = str (a) print (str_a,type (str_a)) # output: 100
Because int and str in python are immutable data types, the str () method here only refers to the data corresponding to the original variable, rather than changing the type of the original variable.
At this point, the study on "how to use int in Python" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.