본문 바로가기
프로그램 개발해서 돈벌기/AI

파이션(python) 초등 완전 기초: 연산과 변수

by ubmuhan 2023. 2. 7.
반응형

출력

print("Hello, world!")

결과: Hello, world!

 

연산

더하기

print(1 + 2)

결과: 3

빼기

print(9 - 5)

결과: 4

 

연산(Operation) 기호(Symbol) 예제
더하기 (Addition) + 1 + 2 = 3
빼기 (Subtraction) - 5 - 4 = 1
곱하기 (Multiplication) * 2 * 4 = 8
나누기 (Division) / 6 / 3 = 2
제곱 (Exponent) ** 3 ** 2 = 9

 

print(((1 + 3) * (9 - 2) / 2) ** 2)

결과: 196.0

 

주석 (Comments)

# Multiply 3 by 2
print(3 * 2)

결과: 6

 

변수 (Variables)

# Create a variable called test_var and give it a value of 4+5
test_var = 4 + 5

# Print the value of test_var
print(test_var)

# >> 9

 

# Set the value of a new variable to 3
my_var = 3

# Print the value assigned to my_var
print(my_var)

# Change the value of the variable to 100
my_var = 100

# Print the new value assigned to my_var
print(my_var)


# >> 3
# >> 100

 

print(my_var)
print(test_var)

# >> 100
# >> 9

 

# Increase the value by 3
my_var = my_var + 3

# Print the value assigned to my_var
print(my_var)

# >> 103

 

# Create variables
num_years = 4
days_per_year = 365 
hours_per_day = 24
mins_per_hour = 60
secs_per_min = 60

# Calculate number of seconds in four years
total_secs = secs_per_min * mins_per_hour * hours_per_day * days_per_year * num_years
print(total_secs)

# >> 126144000

 

# Update to include leap years
days_per_year = 365.25

# Calculate number of seconds in four years
total_secs = secs_per_min * mins_per_hour * hours_per_day * days_per_year * num_years
print(total_secs)

# >> 126230400.0
 
 

 

<< 참조 >>

https://www.kaggle.com/code/alexisbcook/arithmetic-and-variables

 

Arithmetic and Variables

Explore and run machine learning code with Kaggle Notebooks | Using data from No attached data sources

www.kaggle.com

 

 

반응형

댓글