Basic Python Syntax - College of Engineering
Basic Python Syntax
Numbers and Strings
? like Java, Python has built-in (atomic) types
? numbers (int, float), bool, string, list, etc. ? numeric operators: + - * / ** %
>>> a = 5
>>> c = 1.5
>>> s = "hey"
>>> b = 3
>>> 5/2
>>> s + " guys"
>>> type (5) 2
'hey guys'
>>> 5/2.
>>> len(s)
>>> a += 4
2.5
3
>>> a
>>> 5 ** 2
>>> s[0]
9
25
'h'
no i++ or ++i
>>> s[-1]
>>> from __future__ import division 'y'
>>> 5/2 2.5
recommended!
19
Assignments and Comparisons
>>> a = b = 0 >>> a 0 >>> b 0
>>> a, b = 3, 5 >>> a + b 8 >>> (a, b) = (3, 5) >>> a + b >>> 8 >>> a, b = b, a (swap)
>>> a = b = 0 >>> a == b True >>> type (3 == 5) >>> "my" == 'my' True
>>> (1, 2) == (1, 2) True
>>> 1, 2 == 1, 2 ??? (1, False, 2)
20
for loops and range()
? for always iterates through a list or sequence
>>> sum = 0
>>> for i in range(10):
...
sum += i
...
Java 1.5
>>> print sum 45
foreach (String word : words) ! System.out.println(word)
>>> for word in ["welcome", "to", "python"]:
...
print word,
...
welcome to python
>>> range(5), range(4,6), range(1,7,2) ([0, 1, 2, 3, 4], [4, 5], [1, 3, 5])
21
while loops
? very similar to while in Java and C
? but be careful
? in behaves differently in for and while ? break statement, same as in Java/C
>>> a, b = 0, 1
>>> while b ................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- python functions tutorial kart
- python syntax quick reference for some like it tepid project
- conditional statements in python github pages
- python cheat sheet
- python tutorial cheat sheet new york university
- basic python syntax college of engineering
- python language syntax cheat sheet 101 computing
- python if else and nested if else tutorial kart
- control statements
- the python language reference university of idaho
Related searches
- basic python programming examples
- basic python commands
- basic python coding
- basic r syntax cheat sheet
- basic classes for college freshmen
- college of engineering uw madison
- python syntax fixer
- python syntax reference
- python syntax guide
- basic python program
- python syntax cheat sheet
- uf college of engineering ranking