파이썬 기초문법

김한준·2021년 6월 13일
0

Python

목록 보기
1/2
post-thumbnail

1. print

print라는 function 이름이 위치
다음 괄호가 위치
괄호안에 따옴표가 위치
따옴표 안에 출력하고자 하는 string 위치

2. Data type

String - 큰따옴표안에 있는 글자
Interger - 정수
Float - 소수점 숫자
Complex numbers - 실수와 허수를 포함하고 있는 복소수 ex) 1+10j
Boolean - True & False

3. Variable for Strings

알파벳, 숫자, undersocre()로만 구성
첫 글자는 알파벳 or underscore(_)
숫자로 시작 X
알파벳은 대문자 & 소문자 구분
ex) name, _name, my_name, Myname
ex) 10name, my name (X)
  

4. Variable for numbers

주의) 숫자를 변수로 저장할 때 따옴표를 사용하면 String으로 인식
Integer(정수), floating (부동 소수점), miuns(음수)도 값으로 지정 가능
  

5. Advanced math expression

%: modulo operator, 나누기의 나머지 값 ex) 10 % 3 = 1
+= (number): 괄호 안 숫자만큼 증가
-= (number): 괄호 안 숫자만큼 감소
*= (number): 곱하기를 실행한 후 값을 변수에 저장

/=: (number): 나누기를 실행한 후 값을 변수에 저장

6. Concatenating text string

String concatenation - String 을 더함

“Joon”으로 input이 입력되면 “Hello, Joon”

따옴표 앞에 f, 치환하고 싶은 변수를 {}로 사용해서 표시

7. Text replacing

지정된 문자를 새로운 문자로 치환
New_name = name.replace (“지정할 문자”, New_name)
Ex) New = input()
Text = “”” Passion & Beyond key ingredients nutritious honey which moisture leaving rice milk olives enhance retention skin glossy deep moisture body emulsion Beyond Deep Moisture Body Emulsion”””
Text = text.replace (“Beyond”, New)

0개의 댓글