You are on page 1of 7

1

UNIT - 1.
1. INTODUCTION

Python is a popular programming language. It was


created by Guido van Rossum, and released in 1991.

It is used for:

 web development (server-side),


 software development,
 mathematics,
 system scripting.

 Python can be used on a server to create web applications.


 Python can be used alongside software to create workflows.
 Python can connect to database systems. It can also read and
modify files.
 Python can be used to handle big data and perform complex
mathematics.
 Python can be used for rapid prototyping, or for production-ready
software development.

Example:
print("Hello, World!").

2. INPUT PROCESSING AND OUTPUT:

How to Take Input from User in Python:

2
Sometimes a developer might want to take user input at some point in
the program. To do this Python provides an input() function.

Syntax:

input('prompt')

where prompt is an optional string that is displayed on the string at the


time of taking input.

Example 1: Python get user input with a message

# Taking input from the user

name = input("Enter your name: ")

# Output

print("Hello, " + name)

print(type(name))

Output:
Enter your name: GFG
Hello, GFG
<class 'str'>
How to Display Output in Python:

Python provides the print() function to display output to


the standard output devices. 
Syntax: 
Print (value(s), sep= ‘ ‘, end = ‘\n’, file=file, flush=flush)
3
Example: Python Print Output:

# Python program to demonstrate

# print() method

print("GFG")

# code for disabling the softspace feature 

print('G', 'F', 'G')

Output:
GFGG F G

In the above example, we can see that in the case of the 2nd
print statement there is a space between every letter and the
print statement always add a new line character at the end of
the string.

3. DISPLAYING OUTPUT IN PRINT ()FUCTION:

Print () function in Python:


We can use print () function in Python to display some message

or output on Python shell.

The Syntax of print function is:

print(EXPRESSION)

Here EXPRESSION is the variable of any data type or string value

4
that we want to display.

In previous versions of Python there was no need of parenthesis

with print() function but in Python version 3 , it is mandatory to

use pair of parenthesis with print() function.

Examples:
>>>print (“Welcome to Python”) # It is acceptable in Python

version 3

print() automatically inserts a new line character at the end.

4. COMMANDS AND VARIABLES:

Variables:

Variables are containers for storing data values.

Creating Variables:

Python has no command for declaring a variable.

A variable is created the moment you first assign a value to it.

Example
x = 5
y = "John"
print(x)
print(y)

COMMENTS:

5
Python Comments:
Comments can be used to explain Python code.

Comments can be used to make the code more


readable.
Comments can be used to prevent execution when
testing code.

Creating a Comment:

Comments starts with a #, and Python will ignore them:

Example:
#This is a comment
print("Hello, World!")

Python Comments

Comments can be used to explain Python code.

Comments can be used to make the code more readable.

Comments can be used to prevent execution when testing code.

Creating a Comment

Comments starts with a #, and Python will ignore them:

Example
#This is a comment
print("Hello, World!").

6
5. READING INPUT FROM THE KEYBORAD:

User Input:

Python allows for user input.

That means we are able to ask the user for input.

The method is a bit different in Python 3.6 than Python 2.7.

Python 3.6 uses the input() method.

Python 2.7 uses the raw_input() method.

The following example asks for the username, and when you
entered the username, it gets printed on the screen:

Python 3.6
username = input("Enter username:")
print("Username is: " + username).
Example:
username = raw_input("Enter username:")
print("Username is: " + username).

You might also like