[python] 예제 코드 및 결과

[예제 코드]

print("hello")

result = 10print(result)
result = 20print(result)

print("10")
print("20")

hello = "world"world = "hello"
print(hello)
print(world)

password = 12354if password == 1234:
    print("문을 열어줍니다.")
else:
    print("아무궛도 하지 않습니다.")

score = 77
if score >= 90:
    print("A")
elif score >= 80:
    print("B")
elif score >= 70:
    print("C")
else:
    print("F")

#def print_hello():#    print("hello")#print_hello()
def pikachu():
    print('electriC!!!')

pikachu()

def print_message(iamparameter):
    print(iamparameter)

print_message("byte")


def pikachu(skill_number):
    if skill_number == 1:
        print('electric')
    elif skill_number == 2:
        print('gogogo')

pikachu(2)

def plus(val1, val2):
    return val1+val2

#result_return = plus(10,20)#print("result_return =", result_return)
def print_hello(p1,p2):
    print("using print:", p1+p2)

def plus(val1,val2):
    return val1 + val2

result = print_hello(10,20)
result_return = plus(10,20)

print("result",result)

print("result_return",result_return)

'''num_list = [0,1,2,3,4]print(num_list)print(num_list[3])'''
for item in [0,1,2,3,4]:
    print(item)

print(2,1,2)
print(2, "*", 1, "=", 2)

for item in range(1,10):
    print(2, item)

for item in range(1,10):
    print(2,"*",item,"=",2*item)

num_list = [1,2,3,4]

for num in num_list:
    print(num*2)

num_list2 = [1,2,3,4]

results = [num*2 for num in num_list2]

print(results)

a = 10b = -20c = -30total = a+b+c
print(total)

d = 12.5e= 35.8f = 50.4
total2 = d+e+f
average = total / 3print(average)

print(30/4.32423)
print(4/30)
print(5/10)
print(10/5)
print(1/1)
print(type(1))
print(type(1))
print(type(1/1))
print(type(1/1))

print(200 %10)
print(20//7)

tj_kor = 88tj_eng = 76tj_math = 95
yh_kor = 100yh_eng = 67yh_math = 80
tj_average = (tj_kor+tj_eng+tj_math) /3yh_average = (yh_kor+yh_eng+yh_math) /3
if(tj_average > yh_average):
    print("tj win")
    print(tj_average)
elif(tj_average == yh_average):
    print("둘이 같아요")
else:
    print("yh win")



crawling = "data crawling is fun"parsing = 'data parsing is also fun'
print(crawling)
print(parsing)
print(type(crawling))
print(type(parsing))

print(crawling+" ||| "+parsing)

r = 10pie = 3.14area = (r**2) * pie

print("area of circle : " + str(area))

data = crawling[0:4]
data_crawling = crawling[0:13]
fun = crawling[17:]
n = crawling[19]
n_range = crawling[-1:]
also = parsing[16:16+4]

print(data)
print(data_crawling)
print(fun)
print(n)
print(n_range)
print(also)
print(crawling[:-1])

print(crawling.find("data"))
print(crawling.find("fun"))
print(parsing.find("data"))
print(parsing.find("parsing"))
print(parsing.find("also"))
print(crawling.find("parsing"))
print(parsing.find("crawling"))

if(parsing.find("paring") != -1):
    print("paring이 있습니")
else:
    print("paring이 없습니다")

str_data = "random:data:choice:sampling:mini-batch:unpooling:training"split_str_data = str_data.split(":")
print(str_data)
print(split_str_data)

for i in range(0, len(split_str_data)):
    print(split_str_data[i])

print(crawling.replace("data","dodo"))

print(crawling.replace("is", "ok"))

kakaka = "The allegations that Mr Rosenstein discussed invoki" \
         "ng the amendment to oust Mr Trump were first reported last ye" \
         "ar by the New York Times, which cited anonymous sources.However" \
         ", Mr McCabe's quotes are the first to be made on the record from " \
         "someone present at the meeting where the alleged comments were reporte" \
         "dly made.Mr McCabe said Mr Rosenstein had made the remarks in May 2017, a" \
         "fter Mr Trump fired FBI director James Comey."
print(kakaka.count("Trump"))

str_data2 = "{a1 : 20}, {a2:30}, {a3:15},{a4:50},{a5:-15},{a6:80},{a7:0},{a8:-110}"total = 0split_str_data2 = str_data2.split(",")
for i in range(0, len(split_str_data2)):
    str_tmp = split_str_data2[i].split(":")[1].split("}")[0]
    num_tmp = int(str_tmp)
    total += num_tmp
    #print(str_tmp)    #print(total)
print(total)

int_list = [1,2,3,4,5]
float_list = [1.1,2.2,3.3,4.4,5.5]
string_list = ['crawling','parsing','data','extract','preprocessing']
all_list = [int_list, float_list, string_list]

print(int_list)
print(float_list)
print(string_list)
print(all_list)

print(int_list[2:4])
print(float_list[-1:])
print(string_list[1])
print(all_list[0][4])

for i in range(0, len(int_list)):
    print(int_list[i])

for i in range(0, len(float_list)):
    print(float_list[i])

for i in range(0, len(string_list)):
    print(string_list[i])

for i in range(0, len(all_list)):
    print(all_list[i])

int_list.append(6)
print(int_list)
int_list.insert(1,-4)
print(int_list)

int_list.remove(4)
print(int_list)

del int_list[3:]
print(int_list)

int_list.sort()
float_list.sort()
string_list.sort()

print(int_list)
print(float_list)
print(string_list)

class1 = {"vv":"kmk", "tt":"vic"}
print(class1)
print(class1["vv"])
print(class1["tt"])

site = {
    "naver" : "www.naver.com",
    "google" : "www.google.com"}

print(site["naver"])
print(site["google"])

site["daum"] = "www.daum.net"print(site)
print(site["daum"])

site["yahoo"] = "www.yahoo.com"print(site)
print(site["yahoo"])

del site["daum"]
print(site)

print(site.get("naver"))
print(site.get("lycos"))

insert_key = "kakao"if(site.get(insert_key) == None):
    print(insert_key + "에 대한 데이터가 없습니다.")

print(site.keys())
print(site.values())
print(site.items())
print(list(site.keys()))

for key in site.keys():
    print(key)

for value in site.values():
    print(value)

for item in site.items():
    print(item)



[결과]

hello
10
20
10
20
world
hello
아무궛도 하지 않습니다.
C
electriC!!!
byte
gogogo
using print: 30
result None
result_return 30
0
1
2
3
4
2 1 2
2 * 1 = 2
2 1
2 2
2 3
2 4
2 5
2 6
2 7
2 8
2 9
2 * 1 = 2
2 * 2 = 4
2 * 3 = 6
2 * 4 = 8
2 * 5 = 10
2 * 6 = 12
2 * 7 = 14
2 * 8 = 16
2 * 9 = 18
2
4
6
8
[2, 4, 6, 8]
-40
-13.333333333333334
6.937651327519582
0.13333333333333333
0.5
2.0
1.0
<class 'int'>
<class 'int'>
<class 'float'>
<class 'float'>
0
2
tj win
86.33333333333333
data crawling is fun
data parsing is also fun
<class 'str'>
<class 'str'>
data crawling is fun ||| data parsing is also fun
area of circle : 314.0
data
data crawling
fun
n
n
also
data crawling is fu
0
17
0
5
16
-1
-1
paring이 없습니다
random:data:choice:sampling:mini-batch:unpooling:training
['random', 'data', 'choice', 'sampling', 'mini-batch', 'unpooling', 'training']
random
data
choice
sampling
mini-batch
unpooling
training
dodo crawling is fun
data crawling ok fun
2
70
[1, 2, 3, 4, 5]
[1.1, 2.2, 3.3, 4.4, 5.5]
['crawling', 'parsing', 'data', 'extract', 'preprocessing']
[[1, 2, 3, 4, 5], [1.1, 2.2, 3.3, 4.4, 5.5], ['crawling', 'parsing', 'data', 'extract', 'preprocessing']]
[3, 4]
[5.5]
parsing
5
1
2
3
4
5
1.1
2.2
3.3
4.4
5.5
crawling
parsing
data
extract
preprocessing
[1, 2, 3, 4, 5]
[1.1, 2.2, 3.3, 4.4, 5.5]
['crawling', 'parsing', 'data', 'extract', 'preprocessing']
[1, 2, 3, 4, 5, 6]
[1, -4, 2, 3, 4, 5, 6]
[1, -4, 2, 3, 5, 6]
[1, -4, 2]
[-4, 1, 2]
[1.1, 2.2, 3.3, 4.4, 5.5]
['crawling', 'data', 'extract', 'parsing', 'preprocessing']
{'vv': 'kmk', 'tt': 'vic'}
kmk
vic
www.naver.com
www.google.com
{'naver': 'www.naver.com', 'google': 'www.google.com', 'daum': 'www.daum.net'}
www.daum.net
{'naver': 'www.naver.com', 'google': 'www.google.com', 'daum': 'www.daum.net', 'yahoo': 'www.yahoo.com'}
www.yahoo.com
{'naver': 'www.naver.com', 'google': 'www.google.com', 'yahoo': 'www.yahoo.com'}
www.naver.com
None
kakao에 대한 데이터가 없습니다.
dict_keys(['naver', 'google', 'yahoo'])
dict_values(['www.naver.com', 'www.google.com', 'www.yahoo.com'])
dict_items([('naver', 'www.naver.com'), ('google', 'www.google.com'), ('yahoo', 'www.yahoo.com')])
['naver', 'google', 'yahoo']
naver
google
yahoo
www.naver.com
www.google.com
www.yahoo.com
('naver', 'www.naver.com')
('google', 'www.google.com')
('yahoo', 'www.yahoo.com')
[python] 예제 코드 및 결과 [python] 예제 코드 및 결과 Reviewed by kukanuc on 2월 17, 2019 Rating: 5

댓글 없음:

Powered by Blogger.