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

How to use python keywords and identifiers

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

Share

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

This article mainly introduces the relevant knowledge of "how to use python keywords and identifiers". Xiaobian shows you the operation process through actual cases. The operation method is simple, fast and practical. I hope this article "how to use python keywords and identifiers" can help you solve the problem.

keyword

Keywords are words in Python that have been assigned a specific meaning. Developers should not use these keywords in the names of variables, functions, classes, modules, and other objects. The keywords in python are shown in the following table

keyword description and logical operator as create alias assert for debugging break out of loop class definition class continue continue loop def definition function del delete object elif use else in conditional statement except handle exception how to execute False Boolean True Boolean finally handle exception whether exception exists or not will execute a piece of code for creating a for loop from a specific part of the import module global declaration global variable if write conditional statement import module in check list tuples, etc. whether there is a value in a set is testing whether two variables are equal lambda creating anonymous function None null nonlocal declaring nonlocal variable not logical operator or logical operator pass doing nothing raise producing exception return try writing try... except statement while creating while loop with general structure with... as usage yield terminating function Return Generator

Ways to view keywords in python

import keyword

keyword.kwlist

Keyword case sensitivity in Python

All keywords in Python are case-sensitive.

Keyword used as ordinary identifier will report error

identifier

An identifier can simply be understood as a name, for example, everyone has their own name. It is simply the name used to identify variables, functions, classes, modules, and other objects

identifier naming convention

Consists of letters, numbers, underscores. The first character cannot be a number.

Cannot use keywords in Python

For example, the following are legal identifiers

USERID

name

mode2

user_age

Here are illegal identifiers

4word #starts with a number

Try #uses Python keywords

$money #cannot use special characters

Case sensitive

Identifiers in python are strictly case-sensitive. Two identical words, with different case formats, represent completely different meanings.

For example, the following three variables are completely independent and unrelated, just like triplets that look alike and are independent of each other.

number = 0 #all lowercase

Number = 1 #initial capital

NUMBER =2 #ALL CAPITAL

The content of "Python keywords and identifiers how to use" is introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the industry information channel. Xiaobian will update different knowledge points for you every day.

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