Sunday, December 29, 2024

Python -3

 Lists


It is used to store Collection of data.

Lists are created using square brackets:

List Items Order cannot be changed.

It can have duplicate values.


Example


























List Length

use the len() function:
















A list can contain different data types:
















 lists are defined as objects with the data type 'list':























The list() Constructor

Using the list() constructor to make a List:







Access List Items


You can access them by referring to the index number. The index number starts with 0












Negative Indexing


-1 refers to the last item, -2 refers to the second last item etc.













Range of Indexes


You can specify a range of indexes by specifying where to start and where to end the range.














Return the third, fourth, and fifth item:




















We can also ignore the list , by ignoring with the :Index


Example


thislist = ["a", "b", "c",1,2,True,"a","d","c"]
print(thislist)
print(thislist[:3])
#This will return the items from index 0 to index 3











thislist = ["a", "b", "c",1,2,True,"a","d","c"]
print(thislist)
print(thislist[3:])
#This will return the items from index 3 to index end
















Friday, December 27, 2024

Python-2

Creating Comments in Python


Single Line Comment:  Comments starts with a #









We can write comments at the beginning or at the end .  


Multiline Comments














Variable Declaration

Rules for variable declaration


  • A variable name must start with a letter or the underscore character
  • A variable name cannot start with a number
  • A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
  • Variable names are case-sensitive (age, Age and AGE are three different variables)
  • A variable name cannot be any of the Python Keyword.

Invalid Variables Declarations Names












Data Types

















Python Numeric Data Type


Int

Int, or integer, is a whole number, positive or negative, without decimals, of unlimited length.














Float

Float, or "floating point number" is a number, positive or negative, containing one or more decimals.














Float can also be scientific numbers with an "e" to indicate the power of 10














Complex

Complex numbers are written with a "j" as the imaginary part:















Boolean Type


If an expression is True or False.














The bool() function allows you to evaluate any value, and give you   True or False in return,












Any string is True, except empty strings.

Any number is True, except 0.

Any list, tuple, set, and dictionary are True, except empty ones.












  

The following with return False 














Note : Functions can return Boolean values as well.


Example

























String Data Type


We can use single quotation marks, or double quotation marks.

'uday' or "uday".













Multiline Strings:


You can assign a multiline string to a variable by using three quotes:





















Python-1

What is Python?

Python is a popular programming language. It was created by Guido van Rossum, and released in 1991.

It is used for:

Web Development (server-side),

Software development,

Mathematics,

System scripting.


What can Python do?

  • Python can be used on a server to create web applications.
  • Python can be used alongside software to create workflows.
  • Python can connect to database systems. It can also read and modify files.
  • Python can be used to handle big data and perform complex mathematics.
  • Python can be used for rapid prototyping, or for production-ready software development.

Why Python?

  • Python works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc).
  • Python has a simple syntax similar to the English language.
  • Python has syntax that allows developers to write programs with fewer lines than some other programming languages.
  • Python runs on an interpreter system, meaning that code can be executed as soon as it is written


Software Installation

First Method Install Visual Studio  



Then Go to the Extensions., and Then Type Python

























Next Install Jupyter NoteBook Extension













Second Method: Go to the URL 









Note:

Python is an interpreted programming language, this means that as a developer you write Python (.py) files in a text editor and then put those files into the python interpreter to be executed.

Basic Example of Python

Go to Visual Studio Code

File--> New File-







Let us print some sample text 












Python Version

To check the Python version of the editor, you can find it by importing the sys module:






Intro to Python - Syntax

IndentationIndentation refers to the spaces at the beginning of a code line.

We should be using either space or tab while using functions, loops and conditional statements.

In other programming languages we use the Curley braces, which indicates that is a block of code. Where as in the Python we use space or tab








If the indentation is skip, we will get Error














Variables:

Python variables doesn’t need to be embedded with datatype at beginning as python has that capacity to capture the datatype based on the value assigned.

Example: a=10

In above example a is variable, python will assign this variable as int datatype. A is the variable.

Assigning multiple values at the same time.

x,y,z=1,2,3 #This assigns x=1, y=2 and z=3













Variables do not need to be declared with any particular type, and can even change type after they have been set.




Python -3

  Lists It is used to store Collection of data. Lists are created using square brackets: List Items Order cannot be changed. It can have dup...