python入门练习笔记_2

1、

/ 得到商  %得到余数
美国我们用 PEMDAS 这个简称来辅助记忆,它的意思是“括号、指数、乘、除、加、减”——
Parentheses Exponents Multiplication Division Addition Subtraction ——这也是 Python 里的
运算优先级。
2、
= 和 == 有什么不同?
= (single-equal) 的作用是将右边的值赋予左边的变量名。`==` (double-equal) 的作用是检查左右
离岸边是否相等。
3、

格式化字符串(format   string)

%s,表示格化式一个对象为字符
%d,整数
"Hello, %s"%"zhang3" => "Hello, zhang3"
"%d"%33 => "33"
"%s:%d"%("ab",3) => "ab:3"
 
  

%r用rper()方法处理对象

%s用str()方法处理对象

有些情况下,两者处理的结果是一样的,比如说处理int型对象

4、将字符串以\n的形式写就可以分行显示

5、第五行和第六行的代码效果相同

代码片:
days = "Mon Tue Wed Thu Fri Sat Sun"
months ="Jan\nFeb\nMar\nJun\nJul\nAug"

print "Here are the days: %s" % days
print "here are the months: %s" % months
print "here are the months:", months
效果

6、用""".........."""可以打印一段

代码片:

print """
hello
you are 
amazing !!!!
hahahahaha!!!!!
"""
效果:



 
 

猜你喜欢

转载自blog.csdn.net/sinat_25400221/article/details/42916679
今日推荐