Responsive Ad Slot

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