Well, you have gone through a lot of theory to get you started with your first program.

So let’s get your hands dirty.

Go to the command prompt if you are on linux and type : python. You will now be prompted into a shell where you can enter python commands.

Open PyCharm editor to get you started with your first python program. Click on File -> New Project and give the name of the project.

Right click on the project and click New->Python File and give it a name.

TRY IT OUT:

# Create a variable var and assign it a value 7

var = 7

print var

# Change the value of var to 3

var =3

# Here’s some code that will print var to the console:

print var

Here # is used to add comments while you are coding. Comments is a good way to recognize what you are going and it is always a good practice to write your code with comments.

Reserved Words

The following list shows the Python keywords. These are reserved words and they cannot be used as constants or variables.

Whitespace

In Python, whitespace is used to structure code. Whitespace is important, so you have to be careful with how you use it.

TRY IT OUT:

def cricket():

players = 12

return players

print cricket()

def is used to create cricket() which can be called to return players but when you run this function you will get an error saying IndentationError: expected an indented block’.

So you need to indent cricket function to get to know when function started and when it ended.

def cricket():

players = 12

return players

print cricket()

This now will print 12 in the console as you have indented the body of the function.

Things you learned:

and

exec

Not

as

finally

or

assert

for

pass

break

from

print

class

global

raise

continue

if

return

def

import

try

del

in

while

elif

is

with

else

lambda

yield

except

 

 

Recommended Post   How to Install Python on Your System?

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here