摘要:
filename = 'pi_digits.txt' with open(filename) as file_object: lines = file_object.readlines() for line in lines: print(line.rstrip()) open() 接受的参数是当前 阅读全文
摘要:
class Dog: """A simple attempt to model a dog.""" def __init__(self, name, age): """Initialize name and age attributes.""" self.name = name self.age = 阅读全文
摘要:
def getUser(): def关键字定义了一个函数 关键字实参 def getUser(userName, userAge): getUser(userName='张三', userAge=18) 默认值 def getUser(userName, userAge=18): 如果没有传年龄过来 阅读全文
摘要:
input() 可以添加参数显示在控制台 然后获得输入的字符串 int()获得输入的数字 求模运算 4%3 -- 15%3 -- 2 6%3 -- 0 阅读全文
摘要:
字典 alien_0 = {'x_position': 0, 'y_position': 25, 'speed': 'medium'} print(f"Original position: {alien_0['x_position']}") Original position: 0 字典是键值对 感 阅读全文
摘要:
cars = ['audi', 'bmw', 'subaru', 'toyota'] for car in cars: if car == 'bmw': print(car.upper()) else: print(car.title()) if语句 得到的值是Treu 或者 False 注意首字母 阅读全文
摘要:
1 magicians = ['alice', 'david', 'carolina'] 2 for magician in magicians: 3 print(f"{magician.title()}, that was a great trick!") 4 print(f"I can't wa 阅读全文