Friday, November 10, 2006

Python Day 1

Yesterday I started my adventures in learning python, and these are my notes:
First looking at how to run python,

  • Download and install python: http://www.python.org/download
  • Then running commands in the interactive python shell
  • Saving files with a .py extension then running them by using the command:
  • #python name_of_program.py
  • Saving files with a header, therefore running them from a command line.
Then looking at the print command:
*Using quotation marks e.g. "" and '', to print out literal/string statements
*Also adding commas to continue the print expression

Operations:
*Python has six basic operations for numbers:
Exponentiation
**
5 ** 3 == 125
Multiplication
*
2 * 3 == 6
Division
/
14 / 3 == 4
Remainder
%
14 % 3 == 2
Addition
+
1 + 2 == 3
Subtraction
-
4 - 3 == 1
Getting input from a user:
  • raw_input returns a string while
  • input returns a number.
Variable types:
  • type which tells what a variable is, e.g. int, float, string.
  • Numbers are of type int or float (which are short for 'integer' and 'floating point' respectively).
  • strings
The operations with strings do slightly different things than operations with numbers.
Here is the list of some string operations:
Repetition
*
"i" *5 == "iiiii"

Concatenation
+
"Hello, " + "World!" == "Hello, World!"

1 comments:

Erottomaniac said...

Thanks for writingg