Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use variables and identifiers in Python

Shulou Source: shulou.com Published: 2022-06-02 08:16:51 09月16日 Update

This article introduces how to use variables and identifiers in Python, the content is very detailed, interested friends can refer to, I hope it can be helpful to you.

Code implementation

A = 10

A = 'hello'

Print (a) # output hello

_ b123 = 20

Print (_ b123) # output 20

# print = 123

# print (print) # keyword variable output error

Code run output:

Hello

twenty

Program analysis

Variables:

# you cannot use variables that have not been assigned

# if you use a variable that has not been assigned, you will get an error NameError: name 'b'is not defined

# Python is a dynamically typed language, which can assign any type of value to a variable or modify the value of a variable at will

Identifier:

# all content that can be named independently in Python belongs to identifiers # for example: variable names, function names, class names # identifiers must follow the specification of identifiers. Identifiers can contain letters, numbers, and _, but cannot start with a number # example: aqum1 _ A1 _ 1a2. Identifiers cannot be keywords and reserved words in Python and it is not recommended to use function names in Python as identifiers, as this will cause the function to be overwritten by 3. 0. Naming conventions: # follow two naming conventions in Python: # underscore nomenclature # all letters are lowercase, use _ segmentation # max_length min_length hello_world xxx_yyy_zzz# Pascal nomenclature (big hump nomenclature) # the first letter is capitalized, and the first letter of each word is capitalized If the rest of the lowercase # MaxLength MinLength HelloWorld XxxYyyZzz# uses substandard identifiers, it will report an error SyntaxError: invalid syntax is here about how to use variables and identifiers in Python. I hope the above can be helpful to you and you can learn more. If you think the article is good, you can share it for more people to see.

Tags: Identity identifier variable letter output content function code key keyword word uppercase lowercase beginning number more type report help good Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Huawei Linux Xiaomi vpn