Spyder editor 설정
글을 자동으로 맞춰주는 설정이다. 자동으로 줄넘김이 돼서 편하다
코드를 입력하다보면 ' ' , "" 를 사용하게 되는 일이 많은데 따옴표 안에 들어가야 할 내용을 블록 처리 한 후
Ctrl + ' --> 해당 블록 전체 ' ' 지정이 완료
Ctrl + " --> 해당 블록 전체 " " 지정 완료
Print 사용법 기초 ( 문장 줄 넘기기, 문장 띄우기 )
- 다음 줄로 넘기기 \n\
- 문장 띄우기 \t\
다음과 같이 \n\ 을 사용하게 되면 그 기점으로 줄바꾸기 되는 모습을 볼 수 있다.
다음과 같이 \t\을 사용하게 되면 그 기점으로 문자가 tap 되는 모습을 볼 수 있다.
print("Twinkle, Twinkle, little star, \n \
\t How I wonder what you are! \n \
\t\t Up above the world so high, \n \
\t\t Like a diamond in the sky. \n \
Twinkle, Twinkle, little star, \n \
How I wonder what you are!")
숫자형 데이터 타입 (숫자 num , 정수 int , 소수 float, 허수 complex)
- 숫자형
x=1
type(x)
y=2.8
type(y)
z = 1j
type(z)
- 정수형
x=1242141251205120512051250
type(x)
- 소수형
x = 1.1
type(x)
y = 1.0
type(y)
z = -35.59
type(z)
x = 35e3
type(x)
y = 12E4
type(y)
z = -87.7e100
type(z)
- 허수
x = 3+5j
type (x)
y = 5j
type(y)
z= -5j
type(z)
문자형 데이터 타입
"hello"+"hello"
"hello"*3
"hello"[0]
"hello"[-1]
"hello"[1:4]
len("hello")
"hello"<"jello"
"e" in "hello"
print("escapes \n etc,\033")
'single quotes'
"""triple
quotes"""
r"raw \n strings" #r안에 있는 명령어들도 string으로 인식
- 문자 데이터를 추출 할 때 첫번째 글자부터 0, 1, 2, 3 순이다
ex) h e l l o
0 1 2 3 4
- 글자 길이도 추출 할 수 있고 알파벳 순으로 비교연산자 연산도 가능하다 in 을 이용하여 해당 문자열에 같은 값이 있으면 true 없으면 false
ex) txt = "The rain in Spain stays mainly in the plain"
'Spain' in txt --> true
'Spain' not in txt --> false
- \033은 <- 화살표 의미한다.
문자열 포맷팅
print('I eat %d aplles.' % 3)
print('I eat %10s apples.' %'five') #문자열 formating
print('I eat %.2f aplles.' % 3)
print('I eat %10.4f aplles.' % 3.421214213) #소수점자리 세팅
print('I ate %d apples. so I was sick for %s days' % (10,'three'))
print('I eat {:.2f} {} apples.'.format(3, 'red'))
%d 정수 (integer)
%f 실수 (float)
%s 문자열 (string)
이런 의미이다. 위의 결과와 같이 문자들을 format 할 수 있다.
https://blackholecoding.tistory.com/9?category=1032756
https://blackholecoding.tistory.com/10?category=1032756
https://blackholecoding.tistory.com/11?category=1032756
블로그의 PYTHON 기초에서도 각각 데이터 타입에 대한 정보를 찾아 볼 수 있다 !
BYE
'Python(with Anaconda)' 카테고리의 다른 글
[Python] For Loop 반복문 (2) | 2022.10.24 |
---|---|
[Python] If 조건문 (If 조건문을 기반으로 // 키오스크 로직 만들어보기) (0) | 2022.10.24 |
[Python] List 와 Tuple에 대하여 (indexing, slicing, dictionary, split) (list와 tuple 차이) (0) | 2022.10.24 |
[Python] 소득에 따른 세금을 계산하는 프로그램을 만들기! (0) | 2022.10.23 |
[Python] 아나콘다(Anaconda) 설치 및 파이썬 실행 (install python) (2) | 2022.10.21 |
댓글