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 is the use of variables and assignments in Python

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

Share

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

This article mainly shows you "what is the use of variables and assignments in Python", the content is simple and clear, hoping to help you solve your doubts, let me lead you to study and learn "what is the use of variables and assignments in Python" this article.

What is a variable

A variable is the name of something, and the word variable indicates that it is something that changes. Therefore, a variable in Python is a container or storage box whose contents can vary depending on what you put into the container or storage box. For example, to illustrate the variable, there is a cup, we can pour a drink into the cup, the drink can be water, cola and so on. A cup is a container for storing drinks, which is equivalent to the memory or hard disk of a computer, and the drink is equivalent to the data we want to store in the computer. The cup is called a variable in Python, and you can store any type of drink in this cup.

2. What is assignment

Or take the example of cups and drinks. Cups are called variables in Python, and you can store any type of drink in this cup. The process of pouring a drink into a cup is called assignment in Python.

3. Code demonstration

Name = 'Xiao Ming'

This is a common way to assign values to variables. Here name is a variable, and the two words' Xiaoming 'are assigned to the variable name.

4. the characteristics of variables.

The most important feature of a variable is that the data it stores can be changed at any time. Variable is equivalent to a cup, the cup can put anything, but the cup is the size, it can not unlimited stuffing, can only remember the last thing stored. Code demonstration:

So the variable can only print the result of the last assignment in the end.

5. Naming convention of variables.

The name of the variable can not be picked at random, it needs to follow certain norms. Can only contain numbers, letters, and underscores; cannot start with a number; try to describe the data contained. For example, if the assigned information is the name, then the variable name can be name;. If the assigned information is age, then the variable name should be age.

6. = symbol

"=" does not mean equal to, but an assignment, which means to put the content on the right side of the = sign into the variable on the left. = = is the meaning of equals.

These are all the contents of the article "what are variables and assignments in Python?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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