python is easy - It's really easy. Compared to other languages:
Python has no typing: you don't have to declare a variable as an integer/string/whatever.
Python has no strict variable identifiers: you can write whatever you want as a variable within a namespace and expect the interpreter to figure it out at runtime.
Python has dynamic arrays. FTW!
Here's a few examples to get you started. I'm assuming you already have the IDLE environment set up on your computer.
Example 1 - Hello World
1. Open IDLE and make a new window (from the file menu).
2. Save your new window as "test.py" or whatever.
3. Now, in your new python file, type
- Code:
-
print "Hello world!"
4. Run your file with F5.
5. Hello world!
The print command will print some text onto the window: in this case, "Hello World". You can replace that message, or even add another print statement.
Example 2 - Me any My Friend
1. Open up a new file "friend.py" using similar methods as before.
2. To get input from the user, the syntax is:
- Code:
-
raw_input(prompt)
where prompt is the text that displays asking you to input something.
3. So type these:
- Code:
-
friend = raw_input("Enter the name of your first friend: ")
food = raw_input("Enter their favorite food: ")
print "The favorite food of your friend " + friend + " is " + food + "."
4. Test it out!
A line-by-line breakdown.
Line 1 gets input from the user and stores it in a variable called friend1. In this case, the input is the name of your first friend.
Line 2 gets input and stores it in friend2. In this case, the input is the name of your second friend.
Line 3 prints something to the screen. This something is a bunch of different strings attached to one another using concatenation operators - or as you know them, pluses. A string is a series of characters, displayed as text.
That's all for now.