728x90
반응형

참고자료: https://wikidocs.net/12

 

02-1 숫자형

`[동영상 강의]` : [점프 투 파이썬 02-1 숫자형](https://www.youtube.com/watch?v=u_u-41d6V3k&list=PLGSQkvB9T6rvnDop…

wikidocs.net

 

1. 숫자형

 

# 정수형 int

a = 123

a = -178

a = 0

 

# 실수형 float

a = 1.2

a = -3.45

 

# 8진수와 16진수

a = 0o177

print(a) 127

 

a = 0x8ff

b = 0xABC

print(b) 2748

 

 

 

z = 12.3
print(type(z))

a=3
b=4
print(a+b)
print(a-b)
print(a*b)
print(a/b)
print(a**b) # b 의 제곱
print(a%b) #  나머지
print(a//b) # 몫

 

 

 

 

참고자료: https://wikidocs.net/13

 

02-2 문자열 자료형

`[동영상 강의]` : [점프 투 파이썬 02-2 문자열](https://www.youtube.com/watch?v=cKjE94_CITc&list;=PLGSQkvB9T6rvnDo…

wikidocs.net

2. 문자열

c = "Life is too short, You need Python."
# 'Life is \" too short, You need Python.'
# 'Life is " too short, You need Python.'
# """Life is  too short, You need Python."""
d = "a"
e = "123"
print(type(c))
print(type(d))
print(type(e))

# 이스케이프 코드
# \n : 줄바꿈
f = """Life is too short, 
You need Python."""
print(f)

# 문자열 더하기
head = "Python"
tail = " is fun!"
print(head + tail)

# 문자열 곱하기
g="python"
print(g*3)


# 문자열 응용하기
print("=" * 50)
print("My Program")
print("=" * 50)

h = "Life is too short"
print(len(h))


# 문자열의 인덱싱과 슬라이싱
i = "Life is too short, You need Python"
print(i[3])

print(i[0])
print(i[12])
print(i[-2]) # 역으로 진행

 


# 문자열 슬라이싱
i = "Life is too short, You need Python"
j = i[0] + i[1] + i[2] + i[3]
print(j)

# a [ : ]  -> a [이상:미만]
# a [ : : ] -> a [이상:미만:간격]

i = "Life is too short, You need Python"
j = i[19:] # 이상 자리에 비어있으면 처음부터~ 미만 자리에 비어있으면 ~끝까지의 의미이다.
print(j)

i = "Life is too short, You need Python"
j = i[::2] # 처음부터 끝까지 2칸 간격으로 가져오기 
print(j)

i = "Life is too short, You need Python"
j = i[::-1] # 꺼구로 처음부터 끝까지 1칸 간격으로 가져오기 
print(j)

 

a = "20230331Rainy"
date = a[:8]
weather = a[8:]

print(date)
print(weather)

 


# 문자열 포매팅 : 특정 문구에 일부분만 변경 하고 싶을때

c = "I eat %d apples." % 5
print(c)

d = "I eat %s apples." % "five"
print(d)

number = 3
e = "I eat %d apples." % number
print(e)

number = 10
day = "three"
f = "I ate %d apples. so I was sick for %s days." % (number, day)
print(f)

number = 3
e = "I eat %d%% apples." % number
print(e)
# % 자체를 쓰고싶을땐 %% 라고 입력



# 포맷 코드와 숫자 함께 사용하기 ( 이런게 있구나~ )
f="%10s" % "hi"
print(f) 


# 전체길이가 10칸에 글자2칸 빼고 나머지 8칸 띄어쓰기
g="%-10sjane." % 'hi'
print(g)

# 소수점 표현하기
h = "%0.4f" % 3.42134234
print(h)

 


# format 함수 이용하기
i = "I eat {0} apples" .format(3)
print(i)

j = "I eat {0} apples" .format("five")
print(j)

number = 10
day = "three"
k = "I ate {0} apples. so I was sick for {1} days." .format(number, day)
print(k)
# 인덱스 번호 순서대로 인덱스에 맞게 적어주기

# 변수로 적어넣기
l = "I ate {number} apples. so I was sick for {day} days." .format(number=10, day=3)
print(l)

# 혼용가능
l = "I ate {0} apples. so I was sick for {day} days." .format(10, day=3)
print(l)


# 이런게 있다~
# 10칸을 만들고 hi를 적고 왼쪽 정렬을 하겠다
k = "{0:<10}".format("hi")
print(k)
# 10칸을 만들고 hi를 적고 오른쪽 정렬을 하겠다
k = "{0:>10}".format("hi")
print(k)
# 10칸을 만들고 hi를 적고 가운데 정렬을 하겠다
k = "{0:^10}".format("hi")
print(k)

# 10칸을 만들고 hi를 가운데 정렬하고 나머지를 =로 채우겠다
k= "{0:=^10}".format("hi")
print(k)
# 10칸을 만들고 hi를 가운데 정렬하고 나머지를 *로 채우겠다
k= "{0:*^10}".format("hi")
print(k)


# 소수점 표현하기

m = 3.42134234
n = "{0:0.4f}".format(m)
print(n)
# 소수점 4째자리까지 표현하겠다

# {}를 특수기호로 사용할 때 2개를 쓴다.
o = "{{ and }}".format()
print(o)


# 이게 제일 중요!! 이것만 알아도 됌!!
# f 문자열 포매팅
name = '홍길동'
age = 30
p = f'나의 이름은 {name}입니다. 나이는 {age}입니다.'
print(p)

age = 30
p = f'나는 내년이면 {age+1}살이 된다.'
print(p)
# 연산처리도 가능함.

q = f'{"hi":<10}'
print(q)
# 왼쪽 정렬 10글자 

 

 

728x90
반응형

'Data Analysis & Engineer > Python' 카테고리의 다른 글

python 자료형: 불  (0) 2024.01.15
python 자료형: 집합  (2) 2024.01.14
python 자료형: 딕셔너리  (1) 2024.01.12
python 자료형: 튜플  (1) 2024.01.12
python 자료형: 리스트  (1) 2024.01.11
728x90
반응형

참고영상 :

https://youtube.com/playlist?list=PLuHgQVnccGMCgrP_9HL3dAcvdt8qOZxjW&si=yffXdWh3sBOYy1P9

 

 

SHOW DATABASES;


USE opentutorials;


SHOW TABLES;

 

 

# CREATE
CREATE TABLE topic(
id int(11) not null auto_increment,
title varchar(100) not null,
description text null,
created datetime not null,
author varchar(15) null,
profile varchar(200) null,
primary key(id));



# INSERT
SELECT * FROM topic;


INSERT INTO topic (title, description, created, author, profile) 

VALUES('oracle','oracle is...', now(), 'egoing', 'developer');



# SELECT

SELECT id,title, created, author FROM topic; 

--> topic 테이블에 id, title,create,author 칼럼만 출력


SELECT id,title, created, author FROM topic WHERE author='egoing'; 

--> author 칼럼에 'egoing'만 출력


SELECT id,title, created, author FROM topic WHERE author='egoing' ORDER BY id DESC

--> id 칼럼을 내림차순(DESC) 정렬 후 출력


SELECT id,title, created, author FROM topic WHERE author='egoing' ORDER BY id DESC LIMIT 2; 

--> id 칼럼을 내림차순(DESC)으로 정렬하되 그 중 2개만 출력



# UPDATE
UPDATE topic SET description='SQL sever is ...' WHERE id=3;



# DELETE
DELETE FROM topic WHERE id=5;
--> WHERE절 꼭 써야함!


ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ

[관계형 데이터 베이스]

관계형 데이터베이스는 데이터가 하나 이상의 열과 행의 테이블(또는 '관계')에 저장되어 서로 다른 데이터 구조가 어떻게 관련되어 있는지 쉽게 파악하고 이해할 수 있도록 사전 정의된 관계로 데이터를 구성하는 정보 모음입니다.

 


# 테이블이름 변경
RENAME TABLE topic TO topic_backup;



# JOIN
SELECT * FROM topic LEFT JOIN author ON topic.author_id = author.id;
--> topic 테이블 왼쪽에 author 테이블을 join 시키는데

     기준을 topic테이블의 author_id와 author테이블의 id를 맞춰서 join해라.


SELECT topic.id AS topic_id, title, description, created, name, profile from topic left join author on topic.author_id = author.id;
--> id 칼럼이 두군데라 애매모호하다고 해서 topic의 id 칼럼을 topic_id로 이름을 변경하고 조인



728x90
반응형

+ Recent posts