DEV Community

sunj
sunj

Posted on

Python 기초_숫자

  1. 문자 split
# 문자2를 기준으로 문자1을 자른다

text= input('날짜 입력 yyyy.mm.dd')
y,m,d =text.split('.')

y= int(y)
m= int(m)
d= int(d)

print(y,m,d,y+m+d)

Enter fullscreen mode Exit fullscreen mode
  1. map(함수, 집합형태 - iterable객체) 리스트 = []
a,b,c = map(int,['1','2','3'])
print(a,b,c,a+b+c)
Enter fullscreen mode Exit fullscreen mode
a,b,c = map(int,input('a b c 값을 입력하시오').split())

print(a,b,c,a+b+c)
Enter fullscreen mode Exit fullscreen mode
  1. 숫자 출력하기 숫자와 문자가 섞여있는 형태
x=5
y=3
Enter fullscreen mode Exit fullscreen mode
# 숫자와 문자 함께 출력, 콤마 & 형변환
print(x,'과','y','의 합은',x+y,'이다.') # 3 과 5 의 합은 8 이다.

print(str(x)+'과 '+str(y)+'의 합은 '+str(x+y)+'이다.') # 3과 5의 합은 8 이다.
Enter fullscreen mode Exit fullscreen mode
# 숫자와 문자 함께 출력, end = 
print(x,end='')
print('과 ',end='')
print(y,end='')
print('의 합은 ',end='')
print(x+y,end='')
print('이다.',end='')
#3과 5의 합은 8 이다.
Enter fullscreen mode Exit fullscreen mode
#숫자와 문자 함께 출력, format
print('{}과 {}의 합은 {}이다.', format(x,y,x+y))#3과 5의 합은 8 이다.
Enter fullscreen mode Exit fullscreen mode
  1. 연산자 우선 순위

산술 연산자 > 관계 연산자 > 논리 연산자

a ** b 지수

a * b
a / b
a // b
a % b

a + b
a - b

<

<=

'>'

'>='

==

!=

not x

x and y

x or y

ex) 2*5>2+5 and not 3*3> 10 -> true

참조 : 소놀코딩

Top comments (0)