python tutorial | python basics

By | April 1, 2019

So We will start learning python soon so stay tuned..

In this python tutorial we will learn all the python basics.

print function in python

print function is also used for checking our program

escape sequence

‘I\’m Asad’

printing escape sequence

‘I\’m Umer and it is backslash\’

commenting in python

Comments is basically used for documentation to understand other your program.

# is used for comments in python

Strings in python

Anything you write in quotes that is string in python

Python as a calculater:

you can print python as a calculater by writing directly in
print(2+2)

result will be four

for taking power then you have to write two ** instead of one sterick like you use for only multiplication but two sterick is used for
power.

print(4/2) int division
pritn(4//2) float division

difinint variable in python:

for defining variable in python you have to write only variable name for declaring variable donot write datatype for it.

example name = ‘Asad’

print(name)

$ sign is not allowed in defining variable name.
only underscore is allowed.

you cannot start variable name with number or any other sighn with out underscore.

Naming rules

For naming convention there are two convention used.

Camel Case firstName
pascal case FirstName
sanke case e.g second_name
first_name

Strings: Strings in Python can de declared within single quotes or in double quotes.
first_Name = “M”
Second_Name = “Ali”

print(first_Name)
print(last_Name)

Full_Name = First_Name +” ” + second_name
print(Full_name)

Strings concatenation:
Combination of two strings through plus sign called string concatenation.
first_Name = “M”
Second_Name = “Ali”

print(first_Name)
print(last_Name)

Full_Name = First_Name +” ” + second_name
print(Full_name)

String Indexing:
position of characters or integers in memory.

Fist_Name = “Rashid”
Print(first_Name [2] )

We can enter three parameters here
e.g form [0:5:2]

Operation in Strings:

String Slicing: python is functional programming. Phython can support function within function.
first_Name = “Rashid”
print(first_Name [0:5:2] )

slice means To convert into pieces

first_Name = “Rashid”
print(first_Name [0:5:2] )

[initial,final,steps]

final is the point that we want to stop.
steps: That how many steps that we want to jump.
intiail: is the point from which we start our

Immutable strings:
It means that strings cannot be changed.

Input function in python:

name = input(“Enter your name”)

Leave a Reply

Your email address will not be published. Required fields are marked *