Python 第二课 1

一、Numbers:

		>>> 2+2
		4
		>>> 2+4
		6
		>>> 4+ 3
		7
		>>> 2.0 + 1
		3.0
		>>> 3.000 + 5
		8.0
		>>> 15/7
		2.142857142857143
		>>>  50 - (5 + 5)
		 
		SyntaxError: unexpected indent
		>>> 50 - (5 + 5)
		40
		>>> 2 * (5 + 5)
		20
		>>> 2 * 5 / 3
		3.3333333333333335
		>>> 10 / 3 * 2
		6.666666666666667
		>>> 10 //3
		3
		>>> 15 // 4 #向下取整
		3
		>>> 17 % 3 #取余
		2
		>>> 5** 2 #平方
		25
		>>> 3 ** 3
		27
		>>> 3 * * 3
		SyntaxError: invalid syntax
		>>> a = 3
		>>> b = 4
		>>> a ** b
		81
		>>> a + _
		84
		>>> a+ _ #最后打印的表达式被分配给变量_
		87
		>>> _ + _
		174
		>>> _ + 0.123456
		174.123456
		>>> round(_, 2) #截取去小数点后2位之前数值
		174.12
		>>> m = 3+ 2j
		>>> n = 2+4j
		>>> m+n
		(5+6j)

二、Strings

		>>> x = "Hollo World!"
		>>> x
		'Hollo World!'
		>>> y = 'abc'
		>>> y
		'abc'
		>>> 'asldfkjal'
		'asldfkjal'
		>>> 'It\'s a nice idea!'
		"It's a nice idea!"
		>>> 'That\'s ok! \n I love it!' #\转义字符
		"That's ok! \n I love it!"
		>>> 'That\'s ok! \nI love it!'
		"That's ok! \nI love it!"
		>>> s = 'That\'s ok! \n I love it!'
		>>> s
		"That's ok! \n I love it!"
		>>> print(s)
		That's ok! 
		 I love it!
		```
		```>>> print('C:\Program Files\name') #此处\n表示换行
		C:\Program Files
		ame
		>>> print(r'C:\Program Files\name') #此处r表示其中没有转移字符
		C:\Program Files\name
		>>> 

你可能感兴趣的:(Python,python)