Introduction to Python


How to install Python on Linux
How to run a Python program
The basic of Python codes
Data expressions
Built-in functions in Python
Interactive input/output
Conditional statement for Python
Loop structure for Python
Creating your own functions
Python modules
Reading/writing files for Python
Error handling code
Object Oriented Programming (OOP)
Tkinter package for GNU programming

The basic of Python codes

Type declaration can be omitted and simply input numbers or words in a variable. The following is an example:
mes = "Hello World!"
print mes
After runnning the above, you can have
$ Hello World!
You can connect words as a sentence:
a="I "
b="love "
c="New Orleans."
print a+b+c
The output will be
$ I love New Orleans.
For expression of strings, you can use either single or double quotation.

Using numbers without a decimal point is recognized as an integer. Combining decimal numbers and integers results in a float data type.
test = 8e3 + 7**7
print test
The out is following:
$ 831543.0
In python, the complex variables are simply expressed as x+yj.
print u*v
$ (78.1-15.6j)
The basic arithmetic operations are +, -, *, and /. The power is expressed by **. In addition to them, // gives rounded off values.
test2 = 10.0//3.0
print test2
$ 3.0
String parameters can be operated by arithmetic operators shown above. For example,
print "Never give up!\n" * 3
$ Never give up!
$ Never give up!
$ Never give up!
You do not have to declear the type of variables, but you can change it in the context of commands.
print 2 + int(3.0)
print 7.0 + float(4)
$ 5
$ 11.0

Back to Electronics Page

Back to Hiro's Physics Main