Interesting learning python - first words: identifiers, keywords

insert image description here


later

insert image description here

class Person:

    def __init__(self,name):
        self.name = name

    def say_name(self):
        print(f'我的名字是:{
      
      self.name}')

insert image description here

>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not

insert image description here

class:

    def __init__(self,name):
        self.名字 = name

    def 说出你的名字(self):
        print(f'我的名字是:{
      
      self.名字}')


if __name__ == '__main__':
    小李 =("小李")
    小李.说出你的名字()

run and got the result

D:\Worksheet\python\course\example\1>python person.py
我的名字是:小李

insert image description here
naming suggestions for bell

type Naming rules example
module or package name All lowercase letters, simple and meaningful, you can use underscores if necessary math、sys
Function name All lowercase letters, you can use underscores to increase readability foo(), my_func()
variable name All lowercase letters, you can use underscores to increase readability age、my_var
class name Using PascalCase naming rules, the name consists of multiple words, and the first letter of each word is capitalized MyClass
constant name All caps, with underscores for readability LEFT、TAX_RATE

insert image description here
insert image description here
insert image description here

Guess you like

Origin blog.csdn.net/chen565884393/article/details/127391008