You are here

Python Reserve Words and Data Types

Setting the Path

we started working with python in Calculator in Python. But it should also be noted that we need to set the path for the python if not set by default while installing python. This can be done on Windows Plateform  as:

set path=%path%;C:\python37

Typing an end-of-file character (Control-D on Unix, Control-Z on Windows) at the primary prompt causes the interpreter to exit with a zero exit status. If that doesn’t work, you can exit the interpreter by typing the following command: quit()

Interactive Mode

While working with python, we come across two types of prompts these are the primary and secondary prompt.

primary prompt : when you start python prompt that appear is >>>.

Secondary Prompt : … for continuous lines secondary prompt is … (three dots.

>>> # this is primary prompt

>>> the_world_is_flat = True

>>> if the_world_is_flat:

…     print(“Hi, Be careful!”)

…   # this is secondary prompt

Hi, Be careful!

Primary and Secondary Prompt

>>>

In python input and are distinguished by the presence or absence of prompts (>>> and …)

Primary Prompt: In python three greater than symbols are the primary prompt, this is where you write the commands.

Secondary Prompt: In Python the secondary prompt (…) on a line by itself in an example means you must type a blank line; this is used to end a multi-line command.

Prompts and Comment

Output Lines:

Any line that begins without any prompt is the output line in Python.

Comments in Python

A # character before a line is a comment

If # appear in between a string then it is part of string

Reserved Words

The following list shows the Python keywords. These are reserved words and you cannot use them

as constants or variables or any other identifier names. All the Python keywords contain lowercase

letters only.

and

def

finally

is

Print

Yield

assert

del

for

import

Return

as

except

from

lambda

Raise

break

exec

global

Not

Try

class

else

if

or

While

continue

elif

in

Pass

With

Data Types in Python

Python has the following data types built-in by default, in these categories:

Text Type:

str

Numeric Types:

int, float, complex

Sequence Types:

list, tuple, range

Mapping Type:

dict

Set Types:

set, frozenset

Boolean Type:

bool

Binary Types:

bytes, bytearray, memoryview

How to find what data type ?

we can use type() method to find the type of a variable.  Example is illustrated below:

>>> x=”ravi”
>>> print(type(x))             # this will print daata type for variable x
<class ‘str’>

Leave a Reply

Top
error: Content is protected !!