Recent Posts

python variable definition and literal




Hello this is Juny.

python variable is dynamic typing variable.
when you declare any variable, the type of variable is not needed.

let's learn what is variable and
how to declare variable.

let's start.



variable


variable is a indentifier for literal.


we say that we align a value to variable in programming.
in other words, we name it.

for example,

there is 3 value.
and we can call it A.
as a result, A will be variable or identifier for 3.



let's see code.



A=3


we can declare variable like above.


but, there are some rules to name variable.


  • it cannot begin with numbers.
  • you can use alphabet, numbers and underscore(_).
  • capital of alphabet is important. 


for example,


  • 1var (X)
  • 0abc (X)
  • abc1 (O)
  • _ab (O)
  • aaa (O)
  • my_name (O)
  • abc-def (X)
  • abc% (X)
  • AAA (O)
  • Aaa (O)


let's check one of them.


AA = 3
aa = 2
Aa = 1
print(AA ,aa ,Aa )


3 variables are declared.
they have same alphabet A.
but, capital is different from each other.


I print each variable to console.



python_variable_capital



each variable has each value.




literal



literal is representation of value.

for example,
if we assign 3 to A, 3 is literal.

for another example,
if we assign "hello" to B, "hello" is literal.

if we don't assign literal to any variable,
we cannot have reference for the literal.

if you want to reuse the literal,
you have to assign it to any variable.


let's check it in code.



A = 1
2
3
B = "hello"
"bye"
print(A)
print(B)



1 is assigned to A.
2 and 3 is not assigned.
"hello" is assigned to B.
"Bye" is not assigned.

the variables are printed out to console.
literals cannot be printed.
because there is no way to call them.




python variable literal


1 and "hello" are printed out successfully.







python variable definition and literal python variable definition and literal Reviewed by Juny on 7월 07, 2019 Rating: 5

댓글 없음:

Powered by Blogger.