Sunday, October 20, 2024

Python Basic to Advanced Learnings ( Day 2 )

 

Variables

·        Python Variable is containers that store values.

·        Python is not “statically typed”.

·        We do not need to declare variables before using them or declare their type.

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

·        A Python variable is a name given to a memory location.

Restrictions of Python Variables

·        A Python variable name must start with a letter or the underscore character.

·        A Python variable name cannot start with a number.

·        A Python variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ).

·        Variable in Python names are case-sensitive (name, Name, and NAME are three different variables).

·        The reserved words(keywords) in Python cannot be used to name the variable in Python. ( example and,or,if )

Examples of Variables

Declaring and initialization of variables

= ( Equal to ) – is a assignment operator










Redeclaring Variables in python








Assigning Value to Multiple Variables








Assigning Different Values to Multiple Variables








Same Variable Name for Different DataTypes


 
                                                                                   





           

+ operator in Variable                

It will add if it integer, if string concatenate









Different DataTypes in + Operator



 

 

 


 

Datatypes

Data types represent the value type that helps understand what operations you can perform on a particular piece of data.

Built-in Datatypes

Ø  Text Type:    str

Ø  Numeric Types:        int, float, complex

Ø  Sequence Types:      list, tuple, range

Ø  Mapping Type:         dict

Ø  Set Types:   set, frozenset

Ø  Boolean Type:          bool

Ø  Binary Types:            bytes, bytearray, memoryview

Ø  None Type: NoneType

Example of Datatypes ( type () function )

type() function – is a built-in function that returns the type of the objects/data elements stored in any data type.










Libraries in python

·        A Python library is a collection of pre-written code modules that can be used to perform specific tasks in Python programs.

·        Libraries can contain functions, classes, constants, and data values.

·        They can help programmers:

Avoid reinventing the wheel: Libraries can help programmers expedite development by providing reusable code.

Build more robust applications: Libraries can help programmers build more complex applications.

Make everyday tasks more efficient: Libraries can make everyday tasks more efficient. For example, a library like Seaborn can generate visualizations with just one line of code.

Example : Numpy, Panda, Matpolib, pyttsx3, pywhatkit, bokeh

PYTTSX3 Library installation

·        pyttsx3 is a text-to-speech conversion library in Python.

https://pypi.org/project/pyttsx3/

tts – text to speech

pip install pyttsx3 – For installation






pip list | findstr pyttsx3 – to list the installed libraries




Import library, define the library, call the say function from the library



 




Pywhatkit Library Installation

·        pywhatkit is a Python library for sending WhatsApp messages at a certain time, it has several other features too.

https://pypi.org/project/pywhatkit/      

pip install pywhatkit – For installation






pip list | findstr pywhatkit





Help() function - is a built-in function that provides information about modules, classes, functions, and modules.







No comments:

Post a Comment

Python Basic to Advanced Learnings ( Day 3 )

Algorithm in python Definition An algorithm is a list of steps or statements that can be converted into code and executed by a computer....

Popular Posts