ํจ์
def sum(a,b):
result = a + b
return result
def say():
return 'Hi'
def sum(a,b):
print("%d, %d์ ํฉ์ %d์
๋๋ค." %(a, b, +b))
def say():
print('Hi')
def sum_many(*args):
sum = 0
for i in args:
sum = sum+i
return sum
def fun(**kw)
for k in kw.keys():
if(k=="name"):
print("๋น์ ์ ์ด๋ฆ์ :"+k)
a = 1
def vartest():
global a
a = a+1
>> 2
add = lamda a, b: a+b
result = add(3,4)
>> 7
์ฌ์ฉ์์ ์ ๋ ฅ๊ณผ ์ถ๋ ฅ ํจ์(input, print)
number = input("์ซ์๋ฅผ ์
๋ ฅํ์์ค: ")
>> ์ซ์๋ฅผ ์
๋ ฅํ์์ค: 3 #์ฌ์ฉ์์ ์
๋ ฅ
print(number)
>> 3
print("life", "is", "too")
>> life is too
ํ์ผ ์ฝ๊ธฐ ์ฐ๊ธฐ
f = open("์ํ์ผ.txt", 'w')
f.close
๐ ํ์ผ ์ฐ๊ธฐ๋ชจ๋: write() ํจ์
f = open("C:Python/์ํ์ผ.txt", 'w', encoding = "UTF-8")
for i in range(1,11):
data = "%d๋ฒ์งธ ์ค์
๋๋ค.\n" %i
f.write(data)
f.close()
๐ ํ์ผ ์ฝ๊ธฐ๋ชจ๋
1. readline() ํจ์: ํ ์ค์ฉ ์ฝ๊ธฐ
f = open("C:Python/์ํ์ผ.txt", 'w', encoding = "UTF-8")
line = f.readline()
print(line)
f.close()
f = open("C:Python/์ํ์ผ.txt", 'w', encoding = "UTF-8")
lines = f.readlines()
for line in lines:
print(line)
f.close()
๐ ํ์ผ ์ถ๊ฐ๋ชจ๋
with open("foo.txt", 'w') as f:
f.write("Life is too short")