企业开办网站深圳产品展厅设计公司
1. 注释:在Python中,使用井号(#)表示单行注释,三个单引号(''')或三个双引号(""")表示多行注释。
2. 变量:在Python中,不需要声明变量类型,直接赋值即可。例如:
 a = 10
 b = "Hello, World!"
  
3. 数据类型:Python有多种数据类型,如整数(int)、浮点数(float)、字符串(str)、列表(list)、元组(tuple)、集合(set)和字典(dict)。
4. 条件语句:使用if、elif和else关键字进行条件判断。例如:
 age = 18
 if age >= 18:
     print("成年")
 else:
     print("未成年")
  
5. 循环语句:Python中有两种循环语句,分别是for循环和while循环。例如:
 # for循环
 for i in range(5):
     print(i)
# while循环
 count = 0
 while count < 5:
     print(count)
     count += 1
  
6. 函数:使用def关键字定义函数。例如:
 def add(a, b):
     return a + b
result = add(1, 2)
 print(result)
  
7. 类和对象:使用class关键字定义类,通过类创建对象。例如:
 class Person:
     def __init__(self, name, age):
         self.name = name
         self.age = age
    def say_hello(self):
         print(f"Hello, my name is {self.name} and I am {self.age} years old.")
person = Person("Tom", 30)
 person.say_hello()
  
