"파이썬 입문"의 두 판 사이의 차이
DB CAFE
12번째 줄: | 12번째 줄: | ||
## from os import * | ## from os import * | ||
: 모든 함수를 import 하는 방식 | : 모든 함수를 import 하는 방식 | ||
+ | == 변수 == | ||
+ | <source lang=python> | ||
+ | >>> a = 10 | ||
+ | >>> id(a) | ||
+ | </python> | ||
+ | |||
+ | == 데이터 타입 == | ||
+ | <source lang=python> | ||
+ | # int | ||
+ | >>> a = 3 | ||
+ | >>> type(a) | ||
+ | int | ||
+ | </python> | ||
+ | |||
+ | # float | ||
+ | # str | ||
+ | # bool | ||
+ | # complex | ||
+ | <source lang=python> | ||
+ | >>> c = 3 + 4j | ||
+ | >>> type(c) | ||
+ | complex | ||
+ | </python> | ||
+ | |||
+ | == 문자열 조작 함수 == | ||
+ | === len(s) === | ||
+ | <source lang=python> | ||
+ | >>> mystring = “hello world” | ||
+ | >>> len(mystring) | ||
+ | 11 | ||
+ | </source> | ||
+ | |||
+ | === indexing === | ||
+ | <source lang=python> | ||
+ | >>> mystring[0] | ||
+ | ‘h’ | ||
+ | </source> | ||
+ | |||
+ | === slicing === | ||
+ | <source lang=python> | ||
+ | >>> mystring[0:5] | ||
+ | ‘hello’ | ||
+ | |||
+ | >>> mystring[6:] | ||
+ | ‘world’ | ||
+ | </source> | ||
+ | |||
+ | === 문자열.split(S) === | ||
+ | <source lang=python> | ||
+ | >>> companies = “yahoo google” | ||
+ | |||
+ | >>> companies.split(‘ ’) | ||
+ | [‘yahoo’, ‘google’] | ||
+ | </source> | ||
+ | |||
+ | === in === | ||
+ | <source lang=python> | ||
+ | >>> ‘google’ in companies | ||
+ | True | ||
+ | </source> | ||
+ | |||
+ | === combining === | ||
+ | <source lang=python> | ||
+ | >>> s1 = “hello” | ||
+ | >>> s2 = “world” | ||
+ | >>> s3 = s1 + ‘ ’ + s2 | ||
+ | >>> s3 | ||
+ | “hello world” | ||
+ | </source> | ||
+ | |||
+ | === replace === | ||
+ | <source lang=python> | ||
+ | >>> a = “yahoo;google” | ||
+ | >>> new_a = a.replace(‘;’, ‘-’) | ||
+ | >>> new_a | ||
+ | “yahoo-google” | ||
+ | </source> | ||
+ | |||
+ | === index === | ||
+ | <source lang=python> | ||
+ | >>> s = “yahoo google” | ||
+ | >>> s.index(“google”) | ||
+ | 6 | ||
+ | </source> | ||
+ | |||
+ | === 문자열.find(x) === | ||
+ | <source lang=python> | ||
+ | >>> s = “yahoo google” | ||
+ | |||
+ | >>> s.find(“google”) | ||
+ | 6 | ||
+ | </source> | ||
+ | |||
+ | === stripping === | ||
+ | <source lang=python> | ||
+ | >>> a = “ yahoo ” | ||
+ | >>> new_a = a.strip() | ||
+ | >>> new_a | ||
+ | “yahoo” | ||
+ | </source> | ||
+ | |||
+ | |||
[[Category:python]] | [[Category:python]] |
2020년 4월 10일 (금) 09:05 판
thumb_up 추천메뉴 바로가기
- DBA { Oracle DBA 명령어 > DBA 초급 과정 > DBA 고급 과정 }
- 튜닝 { 오라클 튜닝 목록 }
- 모델링 { 데이터 모델링 가이드 }
목차
2 파이썬 모듈 임포트 방법[편집]
- import os
: 일반적인 import 방식
- from os import xxx
: xxx 함수만 import 하는 방식
- from os import *
: 모든 함수를 import 하는 방식
3 변수[편집]
>>> a = 10
>>> id(a)
</python>
== 데이터 타입 ==
<source lang=python>
# int
>>> a = 3
>>> type(a)
int
</python>
# float
# str
# bool
# complex
<source lang=python>
>>> c = 3 + 4j
>>> type(c)
complex
</python>
== 문자열 조작 함수 ==
=== len(s) ===
<source lang=python>
>>> mystring = “hello world”
>>> len(mystring)
11
3.1 indexing[편집]
>>> mystring[0]
‘h’
3.2 slicing[편집]
>>> mystring[0:5]
‘hello’
>>> mystring[6:]
‘world’
3.3 문자열.split(S)[편집]
>>> companies = “yahoo google”
>>> companies.split(‘ ’)
[‘yahoo’, ‘google’]
3.4 in[편집]
>>> ‘google’ in companies
True
3.5 combining[편집]
>>> s1 = “hello”
>>> s2 = “world”
>>> s3 = s1 + ‘ ’ + s2
>>> s3
“hello world”
3.6 replace[편집]
>>> a = “yahoo;google”
>>> new_a = a.replace(‘;’, ‘-’)
>>> new_a
“yahoo-google”
3.7 index[편집]
>>> s = “yahoo google”
>>> s.index(“google”)
6
3.8 문자열.find(x)[편집]
>>> s = “yahoo google”
>>> s.find(“google”)
6
3.9 stripping[편집]
>>> a = “ yahoo ”
>>> new_a = a.strip()
>>> new_a
“yahoo”