python/w3schools

[w3schools] Python Variables - Python Variables

유호야 2021. 5. 20. 22:53
반응형

Creating Variables

Python has no command for declaring a variable.

파이썬은 변수를 선언하는 특별한 명령이 없다.

A variable is created the moment you first assign a value to it.

변수를 처음 할당할 때 선언이 된다.


Variables do not need to be declared with any particular type, and can even change type after they have been set.

변수는 어떤 타입으로 선언될 필요가 없고, 심지어 변수를 선언한 이후에도 타입을 변경할 수 있다. (특정 타입으로 선언하지 않았기 때문)

x = 111 #int정수 타입이 되었겠지만
x = "Sally" #String문자 타입으로 변경할 수가 있다는 말

Casting

If you want to specify the data type of a variable, this can be done with casting.

변수에 대한 데이터 타입을 선언하고 싶으면, 캐스팅을 이용하자

x = int(3)
y = str(3)
z = float(3)

 

Get the Type

You can get the data type of a variable with the type() function.

클래스 타입을 알아보려면
type(변수) 를 print 함수로 출력하면 된다.


Single or Double Quotes?

String variables can be declared either by using single or double quotes:

String 변수는 작은 따옴표와 큰 따옴표 모두로 선언될 수 있다.

x = "John"
x = 'John'
# 둘 다 같은 올바른 값

Case-Sensitive

Variable names are case-sensitive.

변수는 대소문자를 구분한다.

a = "helloaaa"
A = "helloAAA"
print(a)
print(A)

 

출력

helloaaa
helloAAA

 

반응형

'python > w3schools' 카테고리의 다른 글

[w3schools] Assign Multiple Values - Python Variables  (0) 2021.05.25
[w3schools] Variable Names - Python Variables  (0) 2021.05.24
[w3schools] Python Comments  (0) 2021.05.20
[w3schools] Python Syntax  (0) 2021.05.20
[w3schools] Python Intro  (0) 2021.05.20