print(0.1 + 0.2)
import this
#print("hello")
'''
print("hello")
'''
"""
print("hello")
"""
a = "hello world!"
print(a)
print(1+1)
a = 5
print(-a)
print("hello" + "world")
print(type(1))
print(type(1.0))
print(type("sprout"))
a = 1 + 1
b = 1 + 1.0
c = "10" + "0"
d = "hello" + "world"
e = ["a","b"] + ["c","d"]
print(type(print))
print(type(type))
print(type(int))
a = "1"
a = int(a)
b = 1
b = str(b)
int(1.5)
int("sprout")
a = 2.5
b = int(a)
print(a - b)
a = input("可寫可不寫的提示訊息")
name = input("輸入你的名字: ")
print("hello,", name)
Question and Practice
Hi, [name]. You're [age] years old next year.
name = input()
age = int(input())
age = age + 1
# age += 1
age_str = str(age)
print("Hi, " + name + ". You will be " + age_str + " years old next year.")
print("Hi, " + name + ". You will be" , age ,"years old next year.")
print("hello world")
print("hello" )
print ("hello")
print("hello");
print "hello"
print(hello)
print("starburst" "stream")
print("starburst", "stream")
print("starburst", "stream",sep="!!")
print("star", end="")
print("burst", end=" ")
print("stream", end="!")
print("starburst", "stream",sep="!!",end=" RRRRRRR")
什麼時候會用到end?什麼時候會用到sep?
玩玩看 sep 和 end
分別用逗號和 sep 達到和下面程式碼一樣的效果
print("hello" + "world")
"Gura" is a shark
print("\"Gura\" is a shark")
## 讓gura前後的引號可以顯現
print("nnn\nnn")
## \n 會換行
print("ttt\ttt")
## \t 會一次空一個tab
print("xyz\bc")
## b是backspace,會刪掉前一個字元
print("xyzxyz\rabc")
\n 是換行的字元
print(r'\n 是換行的字元')
print(r'hello \nworld')
print(r'hello 'world')
import time
for i in range(9):
i = 9 - i
i = str(i)
print("\r" + i,end="秒")
time.sleep(1)
print("\r" + "0 秒",end="")
print("\nHappy New Year!!!!")
import time
s = "sprout"
l = len(s)
for i in range(l):
print("\r" + s[:l-1-i] + "_", end="")
# print(".",end="")
time.sleep(1)
print("______")
print("hello world")
print("next line!") # 那怎麼不換行
print("a", "b", "c")
print("a" + "b" + "c")
print("a") # " 和 '有差嗎
print('b')
print("I'm Nuss")
# print('I'm Nuss')
a = "world"
b = "Nuss"
c = f"hello {a}, I am {b}"
d = f"hello {a}, I am {b.lower()}"
print(c)
print(d)
# format的格式用法
import math
print(f'The value of pi is approximately {math.pi:.3f}.')
table = {'Sjoerd': 4127, 'Jack': 4098, 'Dcab': 7678}
for name, phone in table.items():
print(f'{name:10} ==> {phone:10d}')
print(f'The value of pi is approximately {math.pi:07.3f}.')