In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "instance Analysis of variables and data types in Python". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Python is a weak data type language, variables do not need to be declared to use, to assign values to variables is to define variables, given the type of value is the type of variable, but the variable is also a data type, the string'1' if you want to participate in the data calculation, you need to use the int () function to convert, use the type () function to view the data type of the variable.
Variables save references to the memory address of the data, python variables are divided into immutable variables and modifiable variables, immutable variables have int,float,str string, tuple, etc., modifiable variables include list list, dict dictionary, set collection and so on. When passing parameters to the function, python always passes references to values, but if the value passed is an unmodifiable variable, a copy will be copied and passed to the function because it is unmodifiable, and how the passed values are modifiable lists, dictionaries, etc., then pass references to these values directly, which can be modified in the function body.
Data types in python:
String: a series of characters enclosed in single or double quotation marks. Using variables in a string can use the f string, which is a new feature introduced in python3.7, which is very convenient to use. Add f before the first quotation mark of the string, you can use {} curly braces in the string to insert the variable into the string, such as f "thisis a {cat}", where cat is a variable name.
Value type: integer int, symbol number float, value type can be used to add, subtract -, multiply *, divide /, multiplier * *, take the remainder% and so on.
List: a comma-separated, ordered, modifiable collection of data enclosed in square brackets []. For example, add elements in the list using the appand () method, insert elements using the insert () method, and delete elements using the de statement, pop () method, or remove () method. The list is sorted using the sort () method, temporary sorting using the sorted () method, reverse order using the reverse () method, taking the list length using the len () method, traversing the list using for. In... Statement.
Tuples: lists are modifiable sets of data, while tuples are immutable lists, enclosed in parentheses (), and separated by commas.
Dictionary: a dictionary is a collection of data of a series of key-value pairs, enclosed in curly braces {}, separated by commas, separated by colons: separated, each key is associated with its value, and keys and values can be any data type, even lists or dictionaries themselves. Some operations of dictionaries are similar to lists, and you can use the get () method to get a key-value pair that may not exist.
This is the end of the content of "instance Analysis of variables and data types in Python". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.