基础
字符串是不可改变的
格式化方法:format()
将一下内容为文件 str_format.py
age = 20 name = 'Swaroop'
print('{0} was {1} years old when he wrote this book'.format(name, age))
print('Why is {0} playing with that python?'.format(name))
输出:
$ python str_format.py
Swaroop was 2
一个学过C/C++的老油条,最近学起了Python,不得不说,知识还是老知识,语法也简单多了,但就是容易搞混。大致总结一下Python与C的区别,以后别张冠李戴啦,嘻嘻。
Part 1.输入与输出
输入任意类型的数据,python用的是input();而C语言对于整型、实型、字符(串)型数据,都可以用scanf。整型/实型scanf(“%d/f”,&x),要加引用符号“&”,而字符串不必加引用符号:scanf(“%s”,x)。对于(单一)字符型数据,用getchar()输入;对于字符串,除了s