Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the formats of variable assignment in python

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "what are the variable assignment formats in python". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what are the variable assignment formats in python".

An overview of 1.Python variables:

Variable, called Variable in English.

Formally, each variable has a unique name, such as axi1

An is the variable and 1 is the value.

From the bottom point of view: all the data in the program should be placed in the memory bar, and the variable is the name of this piece of memory.

Naming of 2.Python variables

Variable name is a kind of identifier, which can not be picked up casually. It must follow the naming rules of Python identifier.

Simple understanding:

An identifier is a name, and its main function is to serve as the name of variables, functions, classes, modules, and other objects.

Just like us, we need a name that is easy to address and refer to.

Naming rules for identifiers: (hump naming for short)

Identifiers are made up of letters (Amurz and amurz), underscores, and numbers. If characters other than these three types of characters appear in the identifier, it must be an illegal identifier.

The first character of an identifier cannot be a number.

The identifier cannot be the same as the Python keyword.

Letters in identifiers are strictly case-sensitive.

Identifiers at the beginning of an underscore have a special meaning, and identifiers that begin with an underscore should be avoided unless required by a particular scenario.

Identifiers can be Chinese characters. But we should try our best to avoid using Chinese characters as identifiers, which will avoid a lot of unnecessary mistakes

3.Python variable assignment 3.1 Overview of Python variable assignment

The assignment of a Python variable refers to the process of putting data into a variable.

Python variables can be assigned directly without declaring a data type. Assigning a value to a variable that does not exist is tantamount to creating (defining) a new variable, in other words, Pyhton must be assigned to create a variable.

The data type of a Python variable can be changed at any time, for example, the same variable can be assigned to a string and an integer.

3.2 basic assignment format of Python variables

3.3 other assignment formats for Python variables

3.3.1 assign the same value to multiple variables at the same time

3.3.2 assign different values to multiple variables at the same time

4 Python variables are worth exchanging

5 View the data type of a variable

To see the data type of the variable, use Python's built-in function type ().

The type () function returns the type of the object.

5.1 get the id identity of the variable in memory a=b=1a=2print (id (a)) print (id (b)) print (id (a))

# result

98647865

98647865

12345689

As you can see from the above code, after the variable is reassigned, the memory address will change.

Is Python a strong or weak language type?

Python is a strongly typed dynamic scripting language

Strong types: different types are not allowed to be added. For example: shaping + string will report a type error.

Dynamic: no display data type declaration is used, and the type of a variable is determined when it is first assigned.

Scripting language: generally an interpretive language, running code requires only an interpreter, not compilation.

Thank you for your reading, the above is the content of "what is the variable assignment format in python". After the study of this article, I believe you have a deeper understanding of what the variable assignment format in python has, 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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report