버미다

고정 헤더 영역

글 제목

메뉴 레이어

버미다

메뉴 리스트

  • 홈
  • 태그
  • 방명록
  • 분류 전체보기 (251) N
    • html, css (83)
    • 서문 (3)
    • python (125) N
    • c언어 (13)
    • gpt활용 (1)
    • pymysql (17)
    • SQLD (8)
    • 업무 (1)

검색 레이어

버미다

검색 영역

컨텐츠 검색

python

  • 슬라이씽

    2024.07.05 by bumychoi

  • 전역변수 & 지역변수

    2024.07.05 by bumychoi

  • 지역변수

    2024.07.05 by bumychoi

  • 전역변수

    2024.07.05 by bumychoi

  • 함수 인자 규칙

    2024.07.04 by bumychoi

  • sigma 계산기

    2024.07.04 by bumychoi

  • 딕셔너리 반복문 활용

    2024.07.04 by bumychoi

  • json 파일 다루기

    2024.07.04 by bumychoi

슬라이씽

# 문자 슬라이씽in_str ="Suppose we have few words that are separated by spaces."li =in_str.split(" ")print(li)count= len(li)print(count)# 예제txt2 =input()b=txt2.split('&',3)print(b)print(f'ex2결과:{b}')['Suppose', 'we', 'have', 'few', 'words', 'that', 'are', 'separated', 'by', 'spaces.'] 10 a&b&c&d&f ['a', 'b', 'c', 'd&f'] ex2결과:['a', 'b', 'c', 'd&f']

python 2024. 7. 5. 17:00

전역변수 & 지역변수

# 지역변수 전역변수def test(x,y):    global a    a=49    x,y =y,x    b=53    b=7    a=135    print(f'step1:{a},{b},{x},{y}')a,b,x,y = 8,13,33,44test(23,7)print(f'step2:{a},{b},{x},{y}')step1:135,7,7,23 step2:135,13,33,44

python 2024. 7. 5. 17:00

지역변수

#지역변수a=20def test():    a=35    return aprint("step:",a)a=100print("step2:",a)print("step3:",test())step: 20 step2: 100 step3: 35 #예제a= 20def test():    global a    print(f'ex3: 결과:{a}')    a=35    return aprint(f"ex1 결과:{a}")a=100print(f'ex2 결과:{a}')print(f'ex4 결과:{test()}')print(f'ex5 결과:{a}')a=7777print(f'ex5 결과{a}')ex1 결과:20 ex2 결과:100 ex3: 결과:100 ex4 결과:35 ex5 결과:35 ex5 결과7777

python 2024. 7. 5. 16:23

전역변수

#전역변수x=100def test():    return x *10print(f'ex1 결과:{test()}')print()# 전역변수 예제 2y=100def test2():    global y    y *=10    return yprint(f'ex2 결과:{test2()}')  ex1 결과:1000 ex2 결과:1000

python 2024. 7. 5. 16:08

함수 인자 규칙

def greet(name,msg="Good morning"):    return "hi~~"+ name +"."+ msgprint(greet("철수"))print(greet("박","how do you do?"))# 모든 인자가 디폴트 값# 모든 인자가 디폴트 값 x# 디폴트 값 인자가 뒤로#예제2def add1(a,b=10,c=15):    return a+b+cprint(f'ex2 결과:{add1(15)}')print(f'ex2 결과:{add1(b=100,c=25,a=30)}')#예제3def add2(*d):    tot=0    for i in d:        tot +=i    return totprint(f'ex3 결과:{add2(10,20,30)}')print(f'ex3 결과:{add2(*..

python 2024. 7. 4. 22:39

sigma 계산기

#sigma calculatorq=int(input("숫자를 입력하세요:"))Sigma=0for i in range(1,q+1):    Sigma +=iprint(Sigma)def sigma_sum(n):    tot =0    for  i in range(1,n+1):        tot= tot+i    return totprint(f'ex1 결과:{sigma_sum(10000)}')#방법2def sigma_sum_2(n):    return n*(n+1)//2print(f'ex2 결과:{sigma_sum_2(10000)}')def sigma_sum_3(n):    return sum(range(n+1))print(f'ex3 결과:{sigma_sum_3(10000)}')

python 2024. 7. 4. 22:04

딕셔너리 반복문 활용

d= dict(one=list(range(1,11)),two=list(range(11,23)),three=list(range(23,37)))print(d)for d,v in d.items():    g=len(v)    print(f'key "{d}"has values"{v}"->total:{g}')

python 2024. 7. 4. 21:48

json 파일 다루기

from urllib import requestimport jsonresponse = request.urlopen("https://jsonplaceholder.typicode.com/users")response_json = response.read()d=json.loads(response_json)print(d)print("---------------------------")from pprint import pprintpprint(d)print("---------------------------")pprint(d,depth=3,indent=4,width=200) [{'id': 1, 'name': 'Leanne Graham', 'username': 'Bret', 'email': 'Sincere@april...

python 2024. 7. 4. 21:37

추가 정보

인기글

최신글

페이징

이전
1 2 3 4 5 6 7 8 ··· 16
다음
TISTORY
버미다 © Magazine Lab
페이스북 트위터 인스타그램 유투브 메일

티스토리툴바