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 writing format of Python and the method of variable naming

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article introduces the relevant knowledge of "what is the writing format of Python and the method of variable naming". In the operation of actual cases, many people will encounter such a dilemma, 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!

1. Command format:

Define variable name

The conditional function ends with ":"

The next command is indented with the space bar, and the Tab key is used by default because it is more obvious.

For example:

YongHuMing = input ('Please enter user name:') yongHuMiMa = input ('Please enter password:) # define variable name if yongHuMing = =' adam' and yongHuMiMa = = '123': print (' login successful') else: print ('wrong username or password') # if the adam user logs in with 123this password, the output is' login successful', otherwise the output 'user wood or password error' II, symbol description:

Use ":" as the tag at the end of the conditional statement

Strings are represented by "'", "", "'" and "".

"#" is used to comment

Using "'" at the beginning indicates that the commands in the middle of the next line that begin with "'" are all comments.

Such as:

YongHuMing = input ('Please enter user name:') # output "Please enter the name:" and define the input value in the variable "yongHuMing" yongHuMiMa = input ('Please enter password:') # output "Please enter password:" and define the input value in the variable "yongHuMiMa" above to define the output text and define the variable name if yongHuMing = = 'adam' and yongHuMiMa = =' 123': # judgment Whether the user name and password match the defined print ('login successful') # if the user name and password match, output "login successful" else: # otherwise print ('wrong user name or password') # otherwise output "wrong user name or password"''if the user whose user name is adam or above uses this password to log in If you enter it correctly, it will show "login succeeded". If there is a wrong user name or password, it will show "wrong user name or password". Variable name:

Letters, numbers, underscores

Numbers cannot be used as the beginning, keywords in python cannot be used.

When using Pinyin as the variable name, the first letter of the second word should be capitalized so that it is easier to identify.

The first letter is in lowercase

For example

JiShuHe = odd sum, yongHuMing = user name, yongHuShuLiang = number of users

This is the end of the content of "what is the Python writing format and variable naming method". Thank you for your 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.

Share To

Development

Wechat

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

12
Report