Python学习笔记2—列表的进阶操作
1. 使用for循环进行列表遍历假设我们有一个魔术师名单,需要将其中每个魔术师的名字都打印出来,则可以用for 循环进行遍历并打印,如: 123magicians = ['alice', 'david', 'carolina']for magician in magicians: print(magician) 这段代码从列表magicians中取出一个名字,并将其存储在变量magician中,进而将其打印,其输出结果如下: 123alice david carolina 2. 创建数值列表2.1 使用函数range()使用函数range()可以生成一些数字,如: 12for value in range(1,5): print(value) 则打印的结果为: 12341 2 3 4 需要注意的是,range(1,5)只是打印数字1-4,并且range(1,5)并不会生成一个包含数字1-4的列表。 2.2...
Python学习笔记1—列表的简单操作
1. 列表的定义在Pyhton中,用[]来表示列表。并用逗号来分隔其中的元素,在下方是一个简单的列表示例,这个列表包含几种自行车: 12bicycles = ['trek', 'cannondale', 'redline', 'specialized']print(bicycles) 下方为打印结果: 1['trek', 'cannondale', 'redline', 'specialized'] 2. 访问列表元素在Python中,可以通过索引来访问列表元素,如: 12bicycles = ['trek', 'cannondale', 'redline',...
Hello World
Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub. Quick StartCreate a new post1$ hexo new "My New Post" More info: Writing Run server1$ hexo server More info: Server Generate static files1$ hexo generate More info: Generating Deploy to remote sites1$ hexo deploy More info: Deployment





