Updated:

1. Basic

  • ๊ธฐ์ดˆ

->๋ฌธ์ž์—ด
print("ใ…‹"*3) #ใ…‹ใ…‹ใ…‹

->boolean
print(5>10) # = print(False) = print(not True) = print(not (5<10))

->๋ณ€์ˆ˜ํ˜•
animal = "๊ณ ์–‘์ด"
name = "ํ•ดํ”ผ"
age = 4
hobby = "๋‚ฎ์ž "
is_adult = age >= 3

print("์šฐ๋ฆฌ์ง‘" + animal + "์˜ ์ด๋ฆ„์€ " + name + "์—์š”")
hobby = "๊ณต๋†€์ด" #์ค‘๊ฐ„์— ๋ฐ”๊ฟ€ ์ˆ˜ ์žˆ์Œ.
print(name + "๋Š” " + str(age) + "์‚ด์ด๋ฉฐ, " + hobby + "์„ ์•„์ฃผ ์ข‹์•„ํ•ด์š”") #๋ณ€์ˆ˜ํ˜•์€ ๋ฌธ์žฅ์•ˆ์— ๋„ฃ์„๋•Œ str์„ ํ•ด์ค˜์•ผํ•œ๋‹ค.
print(name, "๋Š” ", age, "์‚ด์ด๋ฉฐ, ", hobby, "์„ ์•„์ฃผ ์ข‹์•„ํ•ด์š”")
# ๊ฒฐ๊ณผ๋Š” ๊ฐ™๊ณ  ๋ณ€์ˆ˜์— str์„ ํ•ด์ค„ ํ•„์š”๊ฐ€ ์—†๋‹ค..๊ทธ๋Ÿฌ๋‚˜ ๊ณต๋ฐฑ์ด ํฌํ•จ๋œ๋‹ค.
print(name, "๋Š” ", age, "์‚ด์ด๋ฉฐ, ", hobby, "์„ ์•„์ฃผ ์ข‹์•„ํ•ด์š”", sep='')
#sep์„ ๋„ฃ์–ด์ฃผ๋ฉด ๊ณต๋ฐฑ์ด ์—†์–ด์ง„๋‹ค. default๊ฐ€ sep=' '์ด๊ธฐ๋•Œ๋ฌธ์— ๊ณต๋ฐฑ์ด ๋“ค์–ด๊ฐ„๊ฒƒ์ด๋‹ค.
print(name + "๋Š” ์–ด๋ฅธ์ผ๊นŒ์š”? " + str(is_adult))

->์—ฐ์‚ฐ์ž
print(2**3) # 2^3=8 =3์ œ๊ณฑ
print(5//3) # 1 =๋ชซ
  • ์ˆซ์ž์ฒ˜๋ฆฌํ•จ์ˆ˜

print(abs(-5)) # 5
print(pow(4,2)) # 4^2 = 4*4 = 16
print(max(5,12)) # 12
print(min(5,12)) # 5
print(round(3.14)) # 3 ๋ฐ˜์˜ฌ๋ฆผ
print(round(4.99)) # 5 ๋ฐ˜์˜ฌ๋ฆผ
print(divmod(10, 3))  # (3.0, 1.0) ๋ชซ๊ณผ ๋‚˜๋จธ์ง€

from math import *
print(floor(4.99)) # 4 ๋‚ด๋ฆผ
print(ceil(3.14)) # 4 ์˜ฌ๋ฆผ
print(sqrt(16)) # 4 ๋ฃจํŠธ,์ œ๊ณฑ๊ทผ

from random import *
print(random()) #๋žœ๋ค๊ฐ’ 0.0~ 1.0 ๋ฏธ๋งŒ์˜ ์ž„์˜์˜ ๊ฐ’ ์ƒ์„ฑ
print(random() * 10) #๋žœ๋ค๊ฐ’ 0.0~ 10.0 ๋ฏธ๋งŒ์˜ ์ž„์˜์˜ ๊ฐ’ ์ƒ์„ฑ
print(int(random() * 10)) # 0 ~ 10 ๋ฏธ๋งŒ์˜ ์ž„์˜์˜ ๊ฐ’ ์ƒ์„ฑ
print(int(random() * 10) + 1) # 1~10 ๋ฏธ๋งŒ์˜ ์ž„์˜์˜ ๊ฐ’ ์ƒ์„ฑ
print(int(random() * 45) + 1) # 1~45 ์ดํ•˜์˜ ์ž„์˜์˜ ๊ฐ’ ์ƒ์„ฑ

print(randrange(1, 46)) #1~46 ๋ฏธ๋งŒ์˜ ์ž„์˜์˜ ๊ฐ’ ์ƒ์„ฑ
print(randint(1, 45)) #1~45 ์ดํ•˜์˜ ์ž„์˜์˜ ๊ฐ’ ์ƒ์„ฑ

sentence = '๋‚˜๋Š” ์†Œ๋…„์ž…๋‹ˆ๋‹ค' # = "๋‚˜๋Š” ์†Œ๋…„์ž…๋‹ˆ๋‹ค"
sentence2 = """๋‚˜๋Š” ์†Œ๋…„์ด๊ณ ,
ํŒŒ์ด์ฌ์€ ์‰ฌ์›Œ์š”"""
print(sentence2)
  • ์ˆซ์ž์—ด ๋ถ„๋ฆฌํ•˜๊ธฐ

birth = 19920822
year = birth//10000 # 1992
month1 = birth%10000//100 #08
month2 = birth//100%100 #08
date = birth%100 # 22

  • ์Šฌ๋ผ์ด์‹ฑ

jumin = "990120-1234567"
print("์„ฑ๋ณ„ : " + jumin[7])
print("์—ฐ : " + jumin[0:2]) # 0 ๋ถ€ํ„ฐ 2 ์ง์ „๊นŒ์ง€
print("์›” : " + jumin[2:4])
print("์ผ : " + jumin[4:6])
print("์ƒ๋…„์›”์ผ : " + jumin[0:6]) # jumin[0:6]==jum[:6]
print("๋’ค 7์ž๋ฆฌ : " + jumin[7:])
print("๋’ค 7์ž๋ฆฌ (๋’ค์—์„œ๋ถ€ํ„ฐ) : " + jumin[-7:]) # 990120-1234567 ์—์„œ ๋งจ ๋งˆ์ง€๋ง‰์ž๋ฆฌ์ธ 7์€ -1๋ฒˆ์งธ์ด๋‹ค =jumin[-1] ๊ทธ๋Ÿฌ๋ฏ€๋กœ 1์€ jumin[-7]์ด๋‹ค.
  • ๋ฌธ์ž์—ด ์ฒ˜๋ฆฌ

python = "Python is Amazing"
print(python.lower()) # ์ „๋ถ€ ์†Œ๋ฌธ์ž๋กœ ๋ฐ”๊พธ๊ธฐ
print(python.upper()) # ์ „๋ถ€ ๋Œ€๋ฌธ์ž๋กœ ๋ฐ”๊พธ๊ธฐ
print(python[0].isupper()) # 0๋ฒˆ์งธ์ž๋ฆฌ๊ฐ€ ๋Œ€๋ฌธ์ž์ธ๊ฐ€? True
print(len(python)) #๋ฌธ์ž์—ด ๊ธธ์ด
print(python.replace("Python", "Java")) #Java is Amazing
print(python.replace("!", "^-^", 2)) # 3๋ฒˆ์งธ ์ธ์ž ๊ฐฏ์ˆ˜๋งŒํผ ๋ฐ”๊พธ์–ด์ค€๋‹ค. #Python is Amazing^-^^-^
#Python๋ฌธ์ž์—ด๋ถ€๋ถ„์„ Java๋กœ ๋ฐ”๊พธ๊ธฐ
print(python) # Pythio is Amazing. ์ €์žฅ์€ ์•ˆ๋€๋‹ค.

index = python.index("n") # n์€ ๋ช‡๋ฒˆ์งธ์— ์žˆ์„
print(index)
index = python.index("n", index + 1) # n์€ ๋ช‡๋ฒˆ์งธ์— ์žˆ๋Š”๊ฐ€ ์‹œ์ž‘์œ„์น˜๋Š” index+1๋ถ€ํ„ฐ์ด๋‹ค.
print(index)

print(python.find("Python")) # ์žˆ์œผ๋ฉด 0 ์—†์œผ๋ฉด -1
print(python.index("Python")) #  ์žˆ์œผ๋ฉด 0 ์—†์œผ๋ฉด ์˜ค๋ฅ˜

print(python.count("n")) # n ์นด์šดํ„ฐ
  • ๋ฌธ์ž์—ด ๋‚˜๋ˆ„๊ธฐ, ํ•ฉ์น˜๊ธฐ

    ๋‚˜๋ˆ„๊ธฐ : ๋ฌธ์ž์—ด.split(self, sep=None, maxsplit=-1)

    ํ•ฉ์น˜๊ธฐ : ๋ฌธ์ž์—ด.join(self, iterable)
    
    str = "๊ฐ€ ๋‚˜ ๋‹ค ๋ผ ๋งˆ"
    print("str : {0} type: {1}".format(str, type(str)))
    # str : ๊ฐ€ ๋‚˜ ๋‹ค ๋ผ ๋งˆ type: <class 'str'>
    
    str_split = str.split(" ") # list๋กœ ๋ฐ”๋€๋‹ค.
    print("str_split : {0} type: {1}".format(str_split, type(str_split)))
    # str_split : ['๊ฐ€', '๋‚˜', '๋‹ค', '๋ผ', '๋งˆ'] type: <class 'list'>
    
    str_join_comma = ','.join(str_split) # str๋กœ ๋ฐ”๋€๋‹ค
    print("str_join_comma : {0} type: {1}".format(str_join_comma, type(str_join_comma)))
    # str_join_comma : ๊ฐ€,๋‚˜,๋‹ค,๋ผ,๋งˆ type: <class 'str'>
    
    str_join_empty = ''.join(str_split) # str๋กœ ๋ฐ”๋€๋‹ค
    print("str_join_empty : {0} type: {1}".format(str_join_empty, type(str_join_empty)))
    # str_join_empty : ๊ฐ€๋‚˜๋‹ค๋ผ๋งˆ type: <class 'str'>
    
    • ์‘์šฉ

      ์ˆซ์ž / ๋ฌธ์ž์—ด ๋’ค์ง‘๊ธฐ

    # ์ •์ˆ˜ํ˜•์„ ๋ฌธ์ž์—ด๋กœ ๋ณ€ํ™˜
    # ๋ฌธ์ž์—ด์„ ๋ฆฌ์ŠคํŠธ๋กœ ๋ณ€ํ™˜
    # ๋ฆฌ์ŠคํŠธ๋ฅผ ๊ฑฐ๊พธ๋กœ ์ •๋ ฌ
    # ๋ฆฌ์ŠคํŠธ๋ฅผ ๋ฌธ์ž์—ด๋กœ ๋ฐ˜ํ™˜
    num = 123456
    print("num:{0}".format(num)) #123456
    
    str_num = str(num) # ๋ฌธ์ž์—ด ๋ณ€ํ™˜
    print("str_num:{0},type: {1}, str_num[0] : {2} ".format(str_num, type(str_num), str_num[0]))
    # str_num:123456,type: <class 'str'>, str_num[0] : 1
    
    str_list = list(str_num) # ๋ฌธ์ž์—ด์„ ๋ฆฌ์ŠคํŠธ๋กœ ๋ณ€ํ™˜
    str_list.reverse() # reverse๋Š” ๋ฆฌ์ŠคํŠธ์—์„œ๋งŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ธฐ๋•Œ๋ฌธ์— ๋ฆฌ์ŠคํŠธ๋กœ ๋ณ€ํ™˜ํ•ด์ค€๋‹ค
    print("str_list(reverse)  : {0} type: {1}".format(str_list, type(str_list)))
    # str_list(reverse)  : ['6', '5', '4', '3', '2', '1'] type: <class 'list'>
    
    str_list=''.join(str_list) # ๋ฆฌ์ŠคํŠธ์—์„œ ๋ฌธ์ž์—ด๋กœ ๋ณ€ํ™˜ํ•ด์ค€๋‹ค.
    print("str_list(reverse)  : {0} type: {1}".format(str_list, type(str_list)))
    # str_list(reverse)  : 654321 type: <class 'str'>
    
  • ๋ณ€ํ™˜ํ•จ์ˆ˜

    ord : ๋ฌธ์ž์˜ ์•„์Šคํ‚ค ์ฝ”๋“œ๊ฐ’์„ ๋ฆฌํ„ดํ•˜๋Š” ํ•จ์ˆ˜
    hex : hex(x)๋Š” ์ •์ˆ˜๊ฐ’์„ ์ž…๋ ฅ๋ฐ›์•„ 16์ง„์ˆ˜(hexadecimal)๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ ๋ฆฌํ„ดํ•˜๋Š” ํ•จ์ˆ˜
    otc : oct(x)๋Š” ์ •์ˆ˜ ํ˜•ํƒœ์˜ ์ˆซ์ž๋ฅผ 8์ง„์ˆ˜ ๋ฌธ์ž์—ด๋กœ ๋ฐ”๊พธ์–ด ๋ฆฌํ„ดํ•˜๋Š” ํ•จ์ˆ˜
    chr : ์•„์Šคํ‚ค(ASCII) ์ฝ”๋“œ๊ฐ’์„ ์ž…๋ ฅ์œผ๋กœ ๋ฐ›์•„ ๊ทธ ์ฝ”๋“œ์— ํ•ด๋‹นํ•˜๋Š” ๋ฌธ์ž๋ฅผ ๋ฆฌํ„ดํ•˜๋Š” ํ•จ์ˆ˜
    capitalize : ๋‹จ์–ด์˜ ์ฒซ๊ธ€์ž๋งŒ ๋Œ€๋ฌธ์ž๋กœ ๋ณ€ํ™˜ํ•˜๋Š” ํ•จ์ˆ˜

print(ord("A"))       # 65
print(hex(ord("A")))  # 0x41
print(oct(ord("A")))  # 0o101

# chr : ์•„์Šคํ‚ค(ASCII) ์ฝ”๋“œ๊ฐ’์„ ์ž…๋ ฅ์œผ๋กœ ๋ฐ›์•„ ๊ทธ ์ฝ”๋“œ์— ํ•ด๋‹นํ•˜๋Š” ๋ฌธ์ž๋ฅผ ๋ฆฌํ„ดํ•˜๋Š” ํ•จ์ˆ˜
print(chr(65))        # A
print(chr(0x41))      # A

# ๋Œ€์†Œ๋ฌธ์ž ๋ณ€ํ™˜
print(chr(ord('A')+32))  # a
print(chr(ord('Z')+32))  # z
print(chr(ord('a')-32))  # A
print(chr(ord('z')-32))  # Z

# 1์ž๋ฆฌ ์ˆซ์ž ๋ฌธ์ž์—ด์„ ์ˆซ์ž๋กœ ๋ณ€ํ™˜
print(ord('1') - ord('0'), type(ord('1') - ord('0'))) # 1 <class 'int'>
print(ord('9') - ord('0'), type(ord('9') - ord('0'))) # 9 <class 'int'>

# 1์ž๋ฆฌ ์ˆซ์ž๋ฅผ ์ˆซ์ž ๋ฌธ์ž์—ด๋กœ ๋ณ€ํ™˜
print(chr(1 + ord('0')), type(chr(1 + ord('0')))) # 1 <class 'str'>
print(chr(9 + ord('0')), type(chr(9 + ord('0')))) # 9 <class 'str'>

# ์ง„๋ฒ• ์ดˆ๊ธฐํ™”
a = 10
print(type(a), a)
a = 0b10
print(type(a), a)
a = 0o10
print(type(a), a)
a = 0x10
print(type(a), a)
print()
a = 0B10
print(type(a), a)
a = 0O10
print(type(a), a)
a = 0X10
print(type(a), a)
print("-"*20)

# ์ถœ๋ ฅ
i = 0x100
print("i = ", i)
print("i = ", bin(i))
print("i = ", int(i))
print("i = ", oct(i))
print("i = ", hex(i))
print("-"*20)

# ๋ฌธ์ž์—ด์„ ํ˜•๋ณ€ํ™˜
i = "111"
print("i = ", int(i)) # 111
print("i = ", int(i, 2)) # 7
print("i = ", int(i, 8)) # 73
print("i = ", int(i, 16)) # 273
print("i = ", int(i, 5)) # 31
print("-"*20)
  • ๋ฌธ์ž์—ด ํ‘œ

    • ๊ธฐ๋ณธ

    print("๋‚˜๋Š” %d์‚ด์ž…๋‹ˆ๋‹ค." % 20)
    print("๋‚˜๋Š” %s์„ ์ข‹์•„ํ•ด์š”." % "ํŒŒ์ด์ฌ")
    print("Apple์€ %c๋กœ ์‹œ์ž‘ํ•ด์š”." % "A")
    print('๋‚˜์ด๋Š” %03d์„ธ์ด๊ณ  ์‹ ์žฅ์€ %6.2f์ž…๋‹ˆ๋‹ค. ๋‚˜์˜ ์ด๋ฆ„์€ "%s"์ž…๋‹ˆ๋‹ค. '%(33,56.789,'ํ•œ์‚ฌ๋žŒ'))
    #๋‚˜์ด๋Š” 033์„ธ์ด๊ณ  ์‹ ์žฅ์€  56.79์ž…๋‹ˆ๋‹ค. ๋‚˜์˜ ์ด๋ฆ„์€ "ํ•œ์‚ฌ๋žŒ"์ž…๋‹ˆ๋‹ค.
    
    • %s๋Š” ๋‹ค ํฌํ•จํ•  ์ˆ˜ ์žˆ๋‹ค.

    print("๋‚˜๋Š” %s์‚ด์ž…๋‹ˆ๋‹ค. " % 20)
    print("๋‚˜๋Š” %s์ƒ‰๊ณผ %s์ƒ‰์„ ์ข‹์•„ํ•ด์š”." % ("ํŒŒ๋ž€", 20))
    
    • ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•

    print("๋‚˜๋Š” {}์‚ด์ž…๋‹ˆ๋‹ค.".format(20))
    print("๋‚˜๋Š” {}์ƒ‰๊ณผ {}์ƒ‰์„ ์ข‹์•„ํ•ด์š”.".format("ํŒŒ๋ž€", "๋นจ๊ฐ„"))
    print("๋‚˜๋Š” {0}์ƒ‰๊ณผ {1}์ƒ‰์„ ์ข‹์•„ํ•ด์š”.".format("ํŒŒ๋ž€", "๋นจ๊ฐ„"))
    print("๋‚˜๋Š” {1}์ƒ‰๊ณผ {0}์ƒ‰์„ ์ข‹์•„ํ•ด์š”.".format("ํŒŒ๋ž€", "๋นจ๊ฐ„"))
    
    • ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•2

    print("๋‚˜๋Š” {age}์‚ด์ด๋ฉฐ {color}์ƒ‰์„ ์ข‹์•„ํ•ด์š”.".format(age=20, color="๋นจ๊ฐ„"))
    
    • ๋‹ค๋ฅธ ๋ฐฉ๋ฒ• 3 (v3.6์ด์ƒ)

    age = 20
    color = "๋นจ๊ฐ„"
    print(f"๋‚˜๋Š” {age}์‚ด์ด๋ฉฐ, {color}์ƒ‰์„ ์ข‹์•„ํ•ด์š”.")
    
  • ํƒˆ์ถœ๋ฌธ์ž

    • \n : ์ค„๋ฐ”๊ฟˆ

     print("๋ฐฑ๋ฌธ์ด ๋ถˆ์—ฌ์ผ๊ฒฌ \n๋ฐฑ๊ฒฌ์ด ๋ถˆ์—ฌ์ผํƒ€")
      # ๋ฐฑ๋ฌธ์ด ๋ถˆ์—ฌ์ผ๊ฒฌ
      # ๋ฐฑ๊ฒฌ์ด ๋ถˆ์—ฌ์ผํƒ€
    
    • \โ€™,\ " -> ์ €๋Š” โ€œ๋‚˜๋„์ฝ”๋”ฉโ€์ž…๋‹ˆ๋‹ค.

    print("์ €๋Š” \"๋‚˜๋„์ฝ”๋”ฉ\"์ž…๋‹ˆ๋‹ค.")
    print("์ €๋Š” \'๋‚˜๋„์ฝ”๋”ฉ\'์ž…๋‹ˆ๋‹ค.") # ์ €๋Š” "๋‚˜๋„์ฝ”๋”ฉ"์ž…๋‹ˆ๋‹ค.
    
    • \\ : ๋ฌธ์žฅ ๋‚ด์—์„œ \

    # \bin\python์„ ์ถœ๋ ฅํ•˜๋ คํ•จ
    # print("\bin\python") ์˜ค๋ฅ˜
    print("\\bin\\python") #\bin\python
    
    • \r : ์ปค์„œ๋ฅผ ๋งจ ์•ž์œผ๋กœ ์ด๋™

    print("Red Appleeeeee\rPine A") #Pine A
    
    • \b : ๋ฐฑ์ŠคํŽ˜์ด์Šค (ํ•œ ๊ธ€์ž ์‚ญ์ œ)

    print("Redd\bApple") #RedApple
    

  • ํ€ด์ฆˆ

๋ฌธ์ œ

๊ธฐ์ดˆ๋ฌธ๋ฒ•(basic.py)์„ ๋ฐฐ์šด ํ›„ ํ€ด์ฆˆ

Quiz) ์‚ฌ์ดํŠธ๋ณ„๋กœ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ๋งŒ๋“ค์–ด ์ฃผ๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

์˜ˆ) http://naver.com
๊ทœ์น™1 : http:// ๋ถ€๋ถ„์€ ์ œ์™ธ => naver.com
๊ทœ์น™2 : ์ฒ˜์Œ ๋งŒ๋‚˜๋Š” ์ (.) ์ดํ›„ ๋ถ€๋ถ„์€ ์ œ์™ธ => naver
๊ทœ์น™3 : ๋‚จ์€ ๊ธ€์ž ์ค‘ ์ฒ˜์Œ ์„ธ์ž๋ฆฌ + ๊ธ€์ž ๊ฐฏ์ˆ˜ + ๊ธ€์ž ๋‚ด 'e'๊ฐฏ์ˆ˜ + "!"๋กœ ๊ตฌ์„ฑ

์˜ˆ) ์ƒ์„ฑ๋œ ๋น„๋ฐ€๋ฒˆํ˜ธ : nav51!

ํ•ด๋‹ต

sentence = "http://naver.com"
url = sentence
sentence = sentence[7:sentence.index(".")]
print(sentence) #๊ทœ์น™ 1๊ณผ 2 ๋™์‹œ ์ž‘์—… // ๊ทœ์น™1์€ =sentence.replace("http://", "")๋กœ๋„ ํ‘œํ˜„์ด ๊ฐ€๋Šฅํ•˜๋‹ค.
password = sentence[:3] + str(len(sentence)) + str(sentence.count("e")) + "!"
print(f"url์€ {url}์ด๋ฉฐ, ๋น„๋ฐ€๋ฒˆํ˜ธ๋Š” {password}์ž…๋‹ˆ๋‹ค.")
'''
์•„๋ž˜๋Š” ๊ฐ™์€ ์˜๋ฏธ
print("url์€ {1}์ด๋ฉฐ, ๋น„๋ฐ€๋ฒˆํ˜ธ๋Š” {0}์ž…๋‹ˆ๋‹ค.".format(password, url))
print("url์€ %s์ด๋ฉฐ, ๋น„๋ฐ€๋ฒˆํ˜ธ๋Š” %s์ž…๋‹ˆ๋‹ค."%(url, password))
'''

์ถ”๊ฐ€

  • ํ–‰๋ถ„๋ฆฌ : ์—ญ์Šฌ๋ ˆ์‹œ, ๊ด„ํ˜ธ

    ๊ธด ๋‚ด์šฉ์„ ํ•œ์ค„์ธ๊ฒƒ ์ฒ˜๋Ÿผ ์ธ์‹ ์‹œํ‚ค๊ธฐ(\ ์‚ฌ์šฉ)

a = 1 + 2 + 3 + \
      4 + 5 + 6

๊ธด ๋‚ด์šฉ์„ ํ•œ์ค„์ธ๊ฒƒ ์ฒ˜๋Ÿผ ์ธ์‹ ์‹œํ‚ค๊ธฐ(๊ด„ํ˜ธ ์‚ฌ์šฉ

b = (1 + 2 + 3 +
        4 + 5 + 6)

ํŒŒ๋ผ๋ฉ”ํ„ฐ๋ฅผ ๋„˜๊ธฐ๋Š” ๊ฒƒ์ด๋ผ๋ฉด ์ฝค๋งˆ(comma) ๋’ค์—์„œ ๊ทธ๋ƒฅ ์—”ํ„ฐ๋ฅผ ์“ฐ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

print("Hello",  "Python",
          end="\n", sep="\t")

๋ฌธ์ž์—ด ์ค‘๊ฐ„์— ์ค„๋ฐ”๊ฟˆ์„ ํ•˜๋ฉด ์ž๋™์œผ๋กœ โ€œโ€œ๊ฐ€ ์—ด๊ณ ๋‹ซํžˆ๋ฉฐ 1์ค„๋กœ ์ธ์‹ํ•œ๋‹ค.

print("์•„์ฃผ ์•„์ฃผ ์•„์ฃผ ๊ธด ๋ฌธ์ž์—ด์ด๋ผ๊ณ  ๊ฐ€์ •ํ•˜์ž "
         "ํ•œ์ค„์— ๋ชจ๋‘ ํƒ€์ดํ•‘์ด ํž˜๋“ค๋‹ค๋ฉด")
  • ์—ฌ๋Ÿฌ๊ฐœ ๋ณ€์ˆ˜์— ์—ฌ๋Ÿฌ๊ฐ’ ํ• ๋‹นํ•˜๊ธฐ

a=b=c="๋ชจ๋‘๊ฐ™์€ ๊ฐ’"
print("a์˜ ๊ฐ’ : {}".format(a))
print("b์˜ ๊ฐ’ : {}".format(b))
print("c์˜ ๊ฐ’ : {}".format(c))

d,e,f = "ํ•œ์‚ฌ๋žŒ",23,178.9
print("d์˜ ๊ฐ’ : {}".format(d))
print("e์˜ ๊ฐ’ : {}".format(e))
print("f์˜ ๊ฐ’ : {}".format(f))
'''
a์˜ ๊ฐ’ : ๋ชจ๋‘๊ฐ™์€ ๊ฐ’
b์˜ ๊ฐ’ : ๋ชจ๋‘๊ฐ™์€ ๊ฐ’
c์˜ ๊ฐ’ : ๋ชจ๋‘๊ฐ™์€ ๊ฐ’
d์˜ ๊ฐ’ : ํ•œ์‚ฌ๋žŒ
e์˜ ๊ฐ’ : 23
f์˜ ๊ฐ’ : 178.9
'''

  • SWAP

g,h = 100,200
print("g์˜ ๊ฐ’ : {}, h์˜ ๊ฐ’ :{}".format(g,h))
g,h = h,g
print("g์˜ ๊ฐ’ : {}, h์˜ ๊ฐ’ :{}".format(g,h))
'''
g์˜ ๊ฐ’ : 100, h์˜ ๊ฐ’ :200
g์˜ ๊ฐ’ : 200, h์˜ ๊ฐ’ :100
'''
  • ๋ฆฌํ„ฐ๋Ÿด

    0b 2์ง„์ˆ˜
    0o 8์ง„์ˆ˜
    0x 16์ง„์ˆ˜
    j๋กœ ๋๋‚˜๋ฉด ๋ณต์†Œ์ˆ˜์˜ ํ—ˆ์ˆ˜

a = 0b1010
b = 0o310
c = 0x12c
d = 1.1 + 3.14j
print(a, b, c)
print(x, x.real, x.imag)

10 200 300
(1.1+3.14j) 1.1 3.14

์ฐธ์กฐ : https://wikidocs.net/20369

๋Œ“๊ธ€ ์“ฐ๊ธฐ