Responsive Ad Slot

Showing posts with label python. Show all posts
Showing posts with label python. Show all posts

Python Condition Expressions 6 | Learn With Pirates

No comments

Wednesday, 28 April 2021

Python Condition Expressions | Learn With Pirates

Chapter 6: Python Condition Expressions



Conditions in Python

When you login into your social media account's you need to put the correct credential on the portal.
in this case, if your password is not correct they give the statement "please input correct condition". 
so these decisions depend on a condition. In python we able to program with conditions.  

if, else and elif in Python

a=8
if (a==7):
print("Great number")
else:
print("Much Great Number")

Output
Much Great Number
You can see in the example how to use these conditions.

Some operators the use in Python
age = int(input("Enter your age: "))
work_Ex = 4
if(age>18 or work_Ex<56):
print("You can work with us")

else:
print("You cannot work with us")


Output
Enter your age: 19
You can work with us

Relation Operators

Relation operators are used to evaluating conditions inside the if statement. some examples of the relational operator are:
Relational Operator

== #equals
>= #Grater than/ equal to
<= #Less then
!= #Not Equals To

logical Operators

In python logical operator operates on conditional statements example:
Logical Operator
and #Use for both are True
or #One are True
not #invert True to flase

elif condition:

What happens when you have three or more condition how you use if statement: that case you can use with elif
a= int(input("enter number: "))
if (a==0):
print("The value of is 0")
elif(a<0):
print("The valuse of number is nagative")
elif(a>0):
print("The Value of number is positive ")
else:
print("error")


Output
enter number: 6
The Value of number is positive

Note

  • You can declare elif number of you can.
  • last else is execute only if all the if and elif statement fails.

Termination:

If you Like this tutorial please share with your friend and family. I make an amazing tutorial in this blog. If you have any queries and question ask me in the comment section below.

Python Dictionary and Set 5 | Learn With Pirates

No comments

Tuesday, 27 April 2021

Python Dictionary and Set | Learn With Pirates

Chapter 5: Python Dictionary and Set's



Dictionary in Python

Dictionary is a collection of key and value pair in python.
The syntax for the dictionary:
 
Pirates_Dic = {
	"Name": "Pirates",
	"phone":"Android",
	"Os" : "Linux",

}
print(Pirates_Dic['Name'])
print(Pirates_Dic['Os'])
print(Pirates_Dic["phone"])

Output:
Pirates
Linux
Android

   
       
 

Properties of Dictionaries

It unordered
It mutable
It indexed
It, not cantine duplicate keys

Dictionaries Methods

       

# Dictionary Methods
Pirates_Dic = {
    "Name": "Pirates",
    "phone":"Android",
    "Os" : "Linux",
    "Random": {'home':'hotel'},
    1:2
}
print(list(Pirates_Dic.keys())) # Prints the keys of the dictionary #1
print(Pirates_Dic.values()) # Prints the keys of the dictionary #2
print(Pirates_Dic.items()) # Prints the (key, value) for all contents of the dictionary  #3
print(Pirates_Dic) #4
print(Pirates_Dic.get("Os")) # Prints value associated with key "Os" #5

#update Dic

updateDict = {
    "CyberMentor": "Friend",
    "Oday": "Friend",
    "LA": "Friend",
    "Members": "A Family"
}
Pirates_Dic.update(updateDict) # Updates the dictionary by adding key-value pairs from updateDict                                 
print(Pirates_Dic) #6
print(Pirates_Dic.get("LA")) # Prints value associated with key Updated value "LA" #7
                               

Output:
['phone', 'Random', 'Os', 'Name', 1] #1

['Android', {'home': 'hotel'}, 'Linux', 'Pirates', 2] #2

[('phone', 'Android'), ('Random', {'home': 'hotel'}), 
('Os', 'Linux'), ('Name', 'Pirates'), (1, 2)] #3

{'phone': 'Android', 'Random': {'home': 'hotel'}, 
'Os': 'Linux', 'Name': 'Pirates', 1: 2} #4

Linux #5
 
{1: 2, 'Name': 'Pirates', 'LA': 'Friend', 'Random': {'home': 'hotel'}, 'phone': 'Android', 'Oday': 'Friend', 'Members': 'A Family', 'CyberMentor': 'Friend', 'Os': 'Linux'} #6

Friend #7

       
 


Set in Python

Set is a collection of  element
If you are not families with the set take it as a data type that contains a unique value. 
       
#set in Python
a = {1, 3, 4, 5, 1}
print(type(a))
print(a)

Output
type 'set'
set([1, 3, 4, 5])           
  
 

Properties of Set

Set is unorder
Set are unindexed
Once you make a set there is no chance to manipulate them
The set can not con

Set Methods

       
#set Properties
# Creating an empty set
a = set()
print(type(a))

## Adding values to an empty set
a.add(4)
a.add(4)
a.add(5)
a.add(5) # Adding a value repeatedly does not changes a set
a.add((4, 5, 6))

## Accessing Elements
# a.add({4:5}) # Cannot add list or dictionary to sets
print(a)

## Length of the Set
print(len(a)) # Prints the length of this set

## Removal of an Item
a.remove(5) # Removes 5 fromt set a
# a.remove(15) # throws an error while trying to remove 15 (which is not present in the set)
print(a)

print(a.pop())
print(a)

Output
type 'set'>
set([(4, 5, 6), 4, 5])
3
set([(4, 5, 6), 4])
(4, 5, 6)
set([4])

 

Termination:

If you Like this tutorial please share with your friend and family. I make an amazing tutorial in this blog. If you have any queries and question ask me in the comment section below.

Python List and Tuples 4 | Learn With Pirates

No comments

Thursday, 22 April 2021

python list and tuples 4 | Learn With Pirates



Chapater 4: Python List And Tuples

List In Python

Python list is used to store a set of values of any data type.
a = [5,6,7,8,] # Create a list with []

Output
[5, 6, 7, 8]

List Indexing

a = [5,6,7,8,]
# Access using index using a[0], a[1],
print(a[3])

Output
8
the list is an index at 0 to the end of the list
h = [77, "PIrates", True, 7.7] # create with any Data Type
print(h)

Output
[77, 'PIrates', True, 7.7]

Slicing In list:

# slicing in list
word = ["Pirates", "Learn", 66, "like", "tom"]
print(word[0:3])
print(word[-3:])

Output
['Pirates', 'Learn', 66] [66, 'like', 'tom']

List Methods

l1 = [7, 8, 9, 10, 15, 16,]
print(l1)
l1.sort() # sorts the list
print(l1)
l1.reverse() # reverses the list
print(l1)
l1.append(45) # adds 45 at the end of the list
print(l1)
l1.insert(2, 199) # inserts 199 at index 2
print(l1)
l1.pop(2) # removes element at index 2
print(l1)
l1.remove(10) # removes 21 from the list
print(l1)

Output
[7, 8, 9, 10, 15, 16] [7, 8, 9, 10, 15, 16] [16, 15, 10, 9, 8, 7] [16, 15, 10, 9, 8, 7, 45] [16, 15, 199, 10, 9, 8, 7, 45] [16, 15, 10, 9, 8, 7, 45] [16, 15, 9, 8, 7, 45]

Tuples In Python

t = (1, 2, 4, 5) # Creating a tuple using ()
# How to create singal element tuple
t1 = () # Empty tuple
t1 = (7) # Wrong way to declare a Tuple with Single element
t1 = (7,) # Tuple with Single element
print(t1)

print(t[3]) # indexing tuple
output
5



tuples is an immutable data type in python.
t = (1, 2, 4, 5)
t[0] =55
print(t)

Output
TypeError: 'tuple' object does not support item assignment

Note: Once you define tuples that can not be altered or manipulated  

Tuples methods

# consider this tuple
t = (1, 2, 4, 5, 6, 7,)

print(t.count(4)) #return number of time 4 in tuple
print(t.index(6)) #return index value of element

Output
1 4

Termination

If you Like this tutorial please share with your friend and family. I make an amazing tutorial in this blog. If you have any queries and question ask me in the comment section below.

Python String 3 | Learn With Pirates

No comments

Wednesday, 21 April 2021

Python String 3 | Learn With Pirates


Chapter 3: Python String

String is one data type in python

How to identify String

The string is a sequence of character enclose in quotes
p= "pirates"

How to Written String:

  • Single quotes
  • Double quotes
  • Triple quotes
s= 'pirates'     #Single quotes
p= "pirates"     #Double quotes
q= '''pirates''' #Triple quotes
print(s,p,q)

Output
pirates pirates pirates

String Slicing

Main String:
name = "Pirates" #0123456
A String in Python can be sliced for getting a part of the string.
Example For:
name = "Pirates" #0123456
print(name[0:3]) # return 0 to 3 character
print(name[1:3]) # return 1 to 3 character

Output
Pir ir

String index is started counting at 0 to (n-1) in python. 
How work of slice in the string:
slicing= name[int_start: int_end]

Negative indexing:
String index is started negative indexing at -1  to (n-1) in python.
name = "Pirates" #0123456
print(name[-5:-1]) #return same as [2:6]
print(name[2:6])
Output
rate rate

Slicing with skip value:
name = "Pirates" #0123456
print(name[0:6:4]) # return 0 and 4 index

Output
Pt

we can slice whatever we gain from a string.

Advance Slicing Techniques:
name = "Pirates" #0123456
print(name[:6]) # advance Slicing
print(name[0:]) # advance Slicing

Output
Pirate Pirates

Sting Functions:

Main String:
timeline = "Learn with pirates. Hey readers i hope you enjoy this tutorial"

len() function: 
This function returns a length of a string.
timeline = "Learn with pirates. Hey readers i hope you enjoy this tutorial"

print(len(timeline)) # length of timeline

Output
62

string.endwith(word)
this searches your word in the string if the word is present is give True, else False.
timeline = "Learn with pirates. Hey readers i hope you enjoy this tutorial"
print(timeline.endswith("rial")) # True Or False

Output
True

string.count("L")
this function return string total number of character of string.
timeline = "Learn with pirates. Hey readers i hope you enjoy this tutorial"
print(timeline.count("L")) # chracter count L in timeline

Output
1

string.capitalise()
return first character capital of string.
timeline = "Learn with pirates. Hey readers i hope you enjoy this tutorial"
print(timeline.capitalize()) # capitalize first word

Output
Learn with pirates. hey readers i hope you enjoy this tutorial

srinng.find(word)
This is work as a search option. it searches for a word a given answer.
timeline = "Learn with pirates. Hey readers i hope you enjoy this tutorial"
print(timeline.find("readers")) # which index

Output
24

string.replace(old_word,new_word)
this function is use for replace word in to string
timeline = "Learn with pirates. Hey readers i hope you enjoy this tutorial"
print(timeline.replace("Learn", "dO"))# return replace Learn with do

Output
dO with pirates. Hey readers i hope you enjoy this tutorial

Escape Sequence Characters

Identify
a sequence of characters after '\' backslash
Example:
# Escape Sequence Character
'''\n for new line
\t for Tab
\\ backslash
\' for singal quote
'''

Escape = "Pirates are Lead world\'s.\ngoogle\tis\n\\amazing"
print(Escape)

'''Output
Pirates are Lead world.
google is
\amazing'''

Termination

If you Like this tutorial please share with your friend and family. I make an amazing tutorial in this blog. If you have any queries and question ask me in the comment section below.

Python Variable and Data Type 2 | Learn With Pirates

No comments

Python Variable and Data Type 2 | Learn With Pirates



Chapter 2: Python variable and Data Type

Variable is the name of the memory location of the program element.
Example For 

a = 77 #Integer
b = "Pirates" #String
c = 17.0 #float

Data Types

There some data types of python have listed below.

Integer
String
Float
Booleans
None

python is intelligent for identity which data type is for what
like, 

if you write 

a = 77 #identifies as Integer
b = "Pirates" #identifies as String
c = 17.0 #identifies as float



There are some Rule to define a variable 

  • Variable Content alphanumeric, alphabet, underscore
  • a variable name can only start with alphabets and underscore
  • a variable name can not start with numbers
  • space can not contain a variable name.

Operates in Python

In python, we have some common operators.

#arithmetic operators +, -, *, %, /,etc.
#assignment operates =, +=, -=, etc.
#comparison operator ==, !=, <, >, etc.
#logical operator and, or, not.

type() Function

type() function is use for find data type for variable.
a= 50
b= "PIrates"
c= 30.5
print(type(a))
print(type(b))
print(type(c))

Output
<class 'int'>
<class 'str'>
<class 'float'>

Type Casting

numeric variable is converteble like 
a= 50
b= "50"
c= 50.0
print(type(a))
print(type(b))
print(type(c))

Output
<class 'int'>
<class 'str'>
<class 'float'>

input() Function

input() function is used for taking input from the user. every input gives use is by default convert into a string at the output.
a = input("enter a date of your birthdate: ")
print("your birthdate is " +a)

Output
enter a date of your birthdate: 4
your birthdate is 4

NOTE: The user input is a convert to string even you enter the number value. 
Read Chapter 3:
Read Chapter 1:

Termination:

If you Like this tutorial please share with your friend and family. I make an amazing tutorial in this blog. If you have any queries and question ask me in the comment section below.

Python Introduction | Learn With Pirates

No comments

Tuesday, 20 April 2021

Python For Beginner


Chapter 0: Introduction 

What is python?


Python is one of the most popular languages for programming. Python is invented by Guido Van, released in 1991.

 
These are some use of python:
Software development
Mathematics
System scripting
Web development


Some capability of python:

Python can use in web application development
Python can use in artificial intelligent
Python can connect to the database for the application backend


Why do you use python?

Python is platform-independent
It has very simple syntax and structure
With python, the programmer develops application very easy rather then other.

Chapter 1: Python Overview


Python syntax


print(“Hello World”)


Set up the environment for developing amazing things:
The download python for your os

Install with this command:


 

Check the python version with this command:


Write your first code:

 

Note: You use whatever os for this task-it not mandatory to use Linux. 

Here you need one IDE for write python code:

Guide: Download Visual Studio


Comment Python:

A comment is used to write instruction or anything that not going to execute.


Define In code with 

#comment : For singal line Comment

''' comment ''' : For multiline Comment

# This is a singalline comment
''' This
is
a
multiline
comment '''


Module:

The module it a specific task code. That we use as an importing in our program.

Module Types:

Built-In Module: This is a preBuilt module in python. They did not need to install. like os, etc.
 

External Module: This is written by someone to make the task easy for a specific task. They need to import and install. like tensorflow, etc.

import os

print("Hello Pirates")

Using python as a calculator:

You can use Python as calculator as you see into code

print(3+4)
print(3-2)
print(3/2)
print(4%2)

output
7
1
1.5
0

 

Termination

If you Like this tutorial please share with your friend and family. I make an amazing tutorial in this blog. If you have any queries and question ask me in the comment section below.


Don't Miss
© all rights reserved
made with by templateszoo