Practise from from 41 :

 41 : Excercise : Password Checker

username = input("Enter your Usernname: ")
password = input("Enter your Password: ")

passwdencrpy = '*' * 10

print(f"{username}, your password: {passwdencrpy} length is {len(password)} long")

Result

sre, your password: ********** length is 9 long

 =============

Excercise : Password Checker

Slightly Modified the code.

username = input("Enter your Usernname: ")
password = input("Enter your Password: ")

cap_password = int(len(password))
passwdencrpy = '*' * cap_password

print(f"{username}, your password: {passwdencrpy} length is {cap_password} long characters long")

 Result

 Sreejith Balakrishnan, your password: ********** length is 10 long characters long

 

42: List

List is an ordered sequence of object it can be of any type. 

List we denote with square brackets






All the above are valid list values. In Python , lists are a form of array . We will talk about the difference between list and arrays. If you are coming from other programming language list are like array in your language.

This is the first Data-Structure that we are learning. Data structures is a very important concept in programming languages. It is a way for us to organize data lets say into a folder , a cupboard or a box. S that these data structures can be used with various pros and cons .


43: List Slicing :


It starts with 0, and endat 2 and follows goes 1 by 1









 Below is going from the first but skip all the second one


 

 

 

 

 

 

 Strings are immutable but list are mutable




 

 

 

 List are mutable example below.

 


 

 

 

 

 

 

 


 

 

 

 

[:] -- Copy the content 

modifying the list 

new_cart = amazon_cart 

Copying the list 

new_cart = amazon_cart[:]

 


 

 

 

 

 44: Matrix

Matrix is 2D list , it is a multi dimensional list.

matrix = [ [] ] -- Its an array inside of another array.



 

 

 

 

We can also have another inside of this

 


 

 

 

 

 

 Why is this important: These types of matrix comes in a lot in machine learning or image processing

 If you want to list 5 in the first array



 45 : List Methods :

 We have learned about Built-in-Functions , Functions that come with Python

Len function read human readable length it does not start with 0

 


 Lists gets really power when it comes to Methods.

append() method

append does in place append



extend method

pop method, pops off whatever is there in the end of the list

basket.pop(0)  -- will remove the first item in the array.

remove() method

basket.remove(4) // the number 4 in the array gets removed.

clear()

index() method -- tells you the index number for a particular value.

basket = [1,2,3,4,5]

print(basket.index(2))  ans 1

basket = ['a','b','c','d','c']

print(basket.index(d, 0, 2))  search for d from 0 index and end at 2


PYTHON KEYWORDS

in - keyword

basket = ['a','b','c','d','c']

print('d' in basket)  - true



 

Comments

Popular posts from this blog

Datatypes

PYTHON : In 4 hours

Complete Python Developer in 2021 : Zero to Mastery :::