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 basis of Python variables?

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly explains the "what is the basis of Python variables", the content of the explanation is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "what is the basis of Python variables"!

Catalogue

1. What is a variable?

two。 Naming rules for variables

Keywords and reserved words in 3.python

4. Commonly used variable names

5. Assignment of variables

6. The data type of the variable

6.1. Figures

6.2. Boolean type

6.3. String

6.4.type () function

1. What is a variable?

The so-called variable refers to the amount by which its value can be changed during the running of the program.

For example: in mathematics, x and y are variables, but the difference in Python is that variables do not just store numbers, they can store values of any data type.

two。 Naming rules for variables

Variable names can only include letters, numbers, and underscores

You cannot use numbers for a character.

Variable names are case-sensitive in English

Keywords and reserved words cannot be used

Keywords and reserved words in 3.python

Keywords: words that have been given a specific meaning in the Python language, which requires developers not to use these keywords as identifiers to name variables, functions, classes, templates and other objects when developing programs.

Reserved word: the system is reserved (you may never use it, but you can't use it).

Get keywords and reserved words:

Import keywordprint (keyword.kwlist) 4. Commonly used variable names

For example:

The first kind: myName myFriendName

The second kind: MyName MyFriendName

The second kind: my_name my_friend_name

5. Assignment of variables

Python is a dynamic programming language, in the process of program execution, variables can be assigned different types of values, while assigning values also change the data types of variables.

The assignment of a variable does not require a type declaration; Python automatically declares the variable type.

The assignment operator "=" is used to assign values to variables.

For example:

A = 0.01b = 666c = "Hello, Wrold" print (a) print (b) print (c) print

Multivariable assignment

A = 1b = 1c = 1print # code is equivalent to a = b = c = 1print (areco bpenc) a = 1b = 2.2c = "HelloWorld" d = Trueprint (ameme bmeme c) # code is equivalent to a codec d = 1,2.2, "HelloWorld", Trueprint (ameme bparry c) 6. The data type of the variable

The data types of Python include numbers, Boolean, string, tuple, list, dictionary, and so on.

6.1. Figures

Numeric data types are used to store numeric values, including the following three types:

A.int (integer) is often called an integer

B.float (floating-point), also known as floating-point numbers, consists of integers and decimals.

C.complex (plural) consists of real numbers and plural numbers, and the general form is x+yj.

6.2. Boolean type

Bool (Boolean) is a special type, which has only two values: True (true) and False (false) (note case)

6.3. String

Str (string) is any text enclosed in single or double quotation marks, such as' abc', 'abc'

Escape characters begin with\, followed by a character, such as:\'

Python also allows you to precede single quotation marks with r to indicate that strings inside single quotation marks are not escaped by default.

6.4.type () function

Function: returns the type of object

A = 0.01print (type (a)) Thank you for your reading, these are the contents of "what is the basis of Python variables?" after the study of this article, I believe you have a deeper understanding of what is the basis of Python variables, 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