1. 基礎知識
1-1 print:
ex: 想要print "hello world"
-------------------
print("hello world")
Run:
hello world
-------------------
This is one single "OPERAND"
1-2 print, new line character:
"\n" = change line character
-------------------
print("hello\nworld")
Run:
hello
world
-------------------
print("hello \nworld")
Run:
hello
world
-------------------
1-3 print, escape sequence:
\n = change line
\t = horizontal tab
\\ = slash"\"
\' = single quotation" ' "
\" = double quotation " " "
-------------------
a = "Tom\'s brother writes\"1/2 is 0.5\"on his book and Tom\'s book."
print(a)
Run:
Tom's brother writes"1/2 is 0.5"on his book and Tom's book.
-------------------
1-4 simple arithmetic:
+ - * / = 加減乘除
** = 次方
// = 商
% = 取餘
-------------------
candies = 87levelup = candies//7left = candies%7
print ("Power it up %s times and have %s candies left."%(levelup,left))
Run:
Power it up 12 times and have 3 candies left.
-------------------
**補充: 字串格式化
在字串中打"%s",並在最後打%(你要取代的東西)
沒有留言:
張貼留言