본문 바로가기
Python(with Anaconda)

[Python] Spyder editor 간단 사용 팁 및 데이터 타입 형태 (With Aanacond)

by moveho 2022. 10. 22.

Spyder editor 설정

글을 자동으로 맞춰주는 설정이다. 자동으로 줄넘김이 돼서 편하다

Tools --> Preference --> editor --> wrap

코드를 입력하다보면 ' ' , "" 를 사용하게 되는 일이 많은데 따옴표 안에 들어가야 할 내용을 블록 처리 한 후

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

[파이썬] 숫자형 데이터 타입 (Number data type)

2022. 08. 29. 파이썬 실습 파이썬을 컴퓨터에 설치하고 직접 실습한 코드이다. print(-1) print(0) print(1) # int print(1.1) # float print('1+1', 1+1) print('2-1', 2-1) print('2*2', 2*2) print('4/2', 4/2..

blackholecoding.tistory.com

https://blackholecoding.tistory.com/10?category=1032756

[파이썬] 문자 데이터 타입 (String data type)

2022. 08.30. 파이썬에서 직접 실습한 내용이다. print('Hello world') print("Hello world") print(''' Hello world ''') print("'1'+'1'", '1'+'1') print('Hello world'*1000) print("len('Hello world'*1000)"..

blackholecoding.tistory.com

https://blackholecoding.tistory.com/11?category=1032756

[파이썬] 리스트 데이터 타입 (List data type)

2022. 08. 30. 리스트 데이터 타입 파이썬에서 실습한 내용. students = ["egoing", "sori", "maru"] grades = [2,1,4] print("students[1]", students[1]) print("len(students)", len(students)) print("min(gra..

blackholecoding.tistory.com

블로그의 PYTHON 기초에서도 각각 데이터 타입에 대한 정보를 찾아 볼 수 있다 !

BYE

댓글