Professional Documents
Culture Documents
Lecture03 Variables
Lecture03 Variables
Data Types
LECTURE 03
CSC011 - Programming for Scientific Computing
Jennifer Joyce M. Montemayor
Department of Computer Science
School of Computer Studies
MSU - Iligan Institute of Technology
Values and Data Types
‣ a value is one of the fundamental things that a program
manipulates
‣ Be careful when using the lowercase letter l and the uppercase letter O
because they could be confused with the numbers 1 and 0.
5 Jennifer Joyce M. Montemayor / CCC011 / Lecture 01
keywords
‣ cannot be used as variable names
1Letter
max_entries
TWO*FOUR
_variable2
joe’s
float
xYZ123
part#2
XyZ123
this_is_a_long_one
print
max_entries valid
TWO*FOUR invalid, char * is not allowed
_variable2 valid
joe’s invalid, char ‘ is not allowed
float invalid, keyword in Python
xYZ123 valid
part#2 invalid, char # is not allowed
XyZ123 valid
this_is_a_long_one valid
print invalid, function in Python
4score
color12
CONST_TIME
helloworld
two!s
for
elif
@twitter
Gender
_x2y1z0
color12 valid
CONST_TIME valid
helloworld valid
two!s invalid, char ! is not allowed
Gender valid
_x2y1z0 valid
expression
‣ a combination of values, variables, operators, and calls to
functions
Sample operators:
operator operation
+ addition
- subtraction
* multiplication
** exponentiation
/ division
// floor division
% modulo
‣ can take a floating point number, a string, an integer and turn it into
an int
1. Parentheses rule
‣ nested parenthesized expressions must be evaluated from inside out, with the innermost
expression evaluated first
3. Associativity rule
‣ Unary operators in the same subexpression and at the same precedence level are
evaluated right to left (right associativity)
‣ Binary operators in the same subexpression and at the same precedence level are
evaluated left to right (left associativity)
17 Jennifer Joyce M. Montemayor / CCC011 / Lecture 01
Operations on strings
In general, you are not allowed to perform mathematical operations on
strings even if the strings look like numbers
* token works with strings as the repetition operator, given that one
operand is a string and the other operand is an integer
The user of the program can provide the name and hit “enter”
key to signal the interpreter that the value provided by the user
can now be assigned to variable name
‘’’
this is a block / multiple line
comment
‘’’
✓ print values