|
12 years ago 10 |
open a terminal and type $ python
the interpreter starts with >>>
at the prompt type
>>> print("Hello World!")
Hello World!
using python interpreter like a calculator
at the prompt type
>>> 7 + 3 * 4
19
or
>>> (7 + 3) * 4
40
at the prompt type
>>> 9/3
3.0
or
>>> 5.3/6.2
0.85483870967741926
not only with figures available, but also with text
at the prompt type
>>> "hello" * 3
'hellohellohello'
a variable can be assigned values
at the prompt type
>>> a=3
>>> b=4
>>> a*b
12
strings
at the prompt type
>>> "he said \"Mint\"."
'he said "Mint".'
strings put together with operator +
at the prompt type
>>> 'Ulysses ' + 'Manson'
'Ulysses Manson'
strings repeating with operator *
at the prompt type
>>> 'This text is repeated. '*3
'This text is repeated. This text is repeated. This text is repeated. '
first program
create a new text file
in the first line must be a shebang (mostly #!/usr/bin/env python or #!/usr/bin/python)
then paste the following lines in the new text file:
print("hello!")
print("how are you?")
print("I'm fine, and yourself;-)")
print("")
print("I got to go, see you soon")
input("Press any key to terminate the program")
clicking twice starts the program
when everything is finished, the program is terminated
have phun ;-)
Wow, I have to say thank you! This is a quick, awesome, easy tutorial. The combination of completeness and brevity is poetic. I find it inspiring. Thanks again!
It is very good first step. How to continue?