Syntax, Variables, For Loops, and If/Then (Python Basics 1)¶
Basic Syntax¶
- Semi-colons are unnecessary
- Python is whitespace delimited
- “tab in” or use spaces with
forloops orif/thenstatements - “tab out” rather than using
end
- “tab in” or use spaces with
- Use colons with compound statements such as
fororif:
for i in range(10):
print i
Declaring Variables¶
- Python is dynamically typed
- you do not need to declare your variables ahead of time
C
int a;
a = 7;
Python
a = 7
For Loops¶
for i in range(10):
print i
For Loop Examples¶
Github:
https://github.com/ryanGT/python_basics_1
Files:
for_loop.pyfor_loop_2.pyfor_loop_3_two_lists.py
If/Then Statements¶
a = 7
if a == 0:
print('a is zero')
elif a < 5:
print('a is small')
else:
print('a is large')
Github:
https://github.com/ryanGT/python_basics_1/blob/master/if_then_else.py
