Pages

Wednesday, 5 June 2013

[3/??] basic Python

go to 12, 3, 4

Python:types, variables, assignment statements, constant


Python has various type that can be used in it.

str(string in quotes)
int(integer number between -2147483648~2147483647)
long( integer number out of range of int() )
float(real number or float point number)
bool ( boolean values, only two value exist, true or false )



in Python, variables can carry(hold) a value

for example
in this,
string has type of string with 'String value !'

intergervalue has type of int() with 314

floatvalue has 3.14 and type of float point number

(note that type(variable or value) statement shows their input's type)


in Python, a variable does not need to be initiated or declared before use, while other programming languages does need.




when you naming variable or function( and etc), there are a few conventions. the name should be meaningful and descriptive, but short enough. and start with lowercase letter.

examples.
when you are counting something in program, most likely the variable's name would be 'count' or 'count1' something like these..
when you are calculating total of some number, the name will be 'total' or 'sum'.

and when you are calculating something
don't use magic number, like

variable += 1.12


use something like this instead

constant = 1.12
variable += constant

No comments:

Post a Comment