ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 파이썬 - 기본 데이터(정수,실수,문자) 다루는 함수
    파이썬 2017. 11. 17. 13:17

    int -> 정수(1,2,3,..)

    float -> 실수(1.2..등 소수점)

    str -> 문자열


    -타입 확인

    type( 값)



    -출력

     print ('안녕')


    -바인딩

    x=100


    -문자열 바인딩

    >>> mystring = 'hello world' >>> mystring1 = 'a' >>> mystring2 = "a"


    -문자열 인덱싱 및 슬라이싱

    >>> mystring = 'hello world' >>> len(mystring)


    >>> mystring[0:5] 'hello' >>> mystring[6:11] 'world'

    >>> mystring[6:] 'world'

    >>> mystring[:5] 'hello'

    >>> mystring[6:-1] 'worl'


    -스플릿

    >>> my_jusik 'naver daum'

    >>> my_jusik.split(' ') ['naver', 'daum']

    >>> my_jusik.split(' ')[0] 'naver'

    >>> split_jusik = my_jusik.split(' ') >>> split_jusik ['naver', 'daum'] >>> print(split_jusik[0]) naver


    -문자열 합치기

    >>> daum + kakao 'DaumKAKAO'

    >>> daum_kakao = daum + ' ' + kakao >>> daum_kakao 'Daum KAKAO'


    -주소찾기

    id(x)


    -연습문제

    문제 2-1

    >>> daum = 89000
    >>> naver = 751000
    >>> total = daum * 100 + naver * 20
    >>> print(total)
    23920000

    문제 2-2

    >>> daum = 89000
    >>> naver = 751000
    >>> loss = (daum * 0.05 * 100) + (naver * 0.1 * 20)
    >>> print(loss)
    1947000.0

    문제 2-3

    >>> f = 50
    >>> c = (f-32) / 1.8
    >>> print(c)
    10.0

    문제 2-4

    >>> print("pizza\n" * 10)
    pizza
    pizza
    pizza
    pizza
    pizza
    pizza
    pizza
    pizza
    pizza
    pizza
    

    문제 2-5
    >>> monday_start_price = 1000000
    >>> monday_end_price = monday_start_price * 0.7
    >>> tuesday_start_price = monday_end_price
    >>> tuesday_end_price = tuesday_start_price * 0.7
    >>> wednesday_start_price = tuesday_end_price
    >>> wednesday_end_price = wednesday_start_price * 0.7
    >>> print(wednesday_end_price)
    342999.99999999994

    문제 2-6

    >>> print("이름: 파이썬 생년월일: 2014년 12월 12일 주민등록번호: 20141212-1623210")
    이름: 파이썬 생년월일: 20141212일 주민등록번호: 20141212-1623210

    문제 2-7

    >>> s = 'Daum KaKao'
    >>> s = s[5:] + ' ' + s[0:4]
    >>> s
    'KaKao Daum'

    문제 2-8

    >>> a = 'hi ' + a[6:]
    >>> a
    'hi world'

    문제 2-9

    >>> x = 'abcdef'
    >>> x = x[1:]+x[0]
    >>> x
    'bcdefa'