0% found this document useful (0 votes)
8 views8 pages

Core Python Programming Concepts

Bchjb

Uploaded by

thinkpositive574
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views8 pages

Core Python Programming Concepts

Bchjb

Uploaded by

thinkpositive574
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

CORE PYTHON NOTES:

PYTHON WAS INTRODUCED BY GUIDO VON ROSSUM IN THE YEAR OF 1991.

FEATURES OF PYTHON:
[Link] TO LEARN AND ANALYSE

[Link] TYPED LANGUAGE

[Link] IS HIGHLY EFFICIENT

[Link] LANGUAGE

[Link] LANGUAGE

[Link] HUGE NUMBER OF LIBRARIES

[Link] MULTIPARADIGM (SUPPORTS OOPS, POPS, FUNCTIONAL WAY OF PROGRAMMING)

INTRODUCTION TO LIBRARY FUNCTION:


DEFINITON: LIBRARY FUNCTIONS ARE PREDEFINED FUNCTION WHOSE TASK IS ALREADY DEFINED BY
THE DEVOLOPER WE CAN USE THE FUNCTIONALITY OF THOSE FUNCTION BUT WE CAN’T MODIFY
THEM.

3 TYPES OF LIBRARY FUNCTION WE HAVE IN PYTHON:

[Link]

[Link]

[Link] FUNTION

INTRODUCTION TO KEYWORD:
KEYWORDS ARE NOTHING BUT RESERVED WORDS WHOSE TASK IS ALREADY DEFINED BY THE
DEVOLOPERS WE CAN ACCESS THE FUNCTIONALITY OF THOSE KEYWORDS BUT WE CAN’T MODIFY
THEM.

THE SYNTAX TO KNOW ALL THE KEYWORDS WHICH WE HAVE IN PYTHON:

import
importkeyword
keyword
[Link]
[Link]
HERE IN CASE OF PYTHON WE HAVE 35 KEYWORDS.

IN THOSE 35 KEYWORDS WE HAVE 3 SPECIAL KEYWORDS

[Link]

[Link]

[Link]

These are called as special keyword because we can assign these keywords as a value to a variable.
a=True -----→it is possible

a=if-------→not possible because they are not special keywords

VARIABLES:
VARIABLE ARE NOTHING BUT THE NAMED MEMORY LOCATION WHERE WE CAN STORE OUR
[Link] ACT LIKE A CONTAINER FOR STORING VALUES.

a=90

HERE, a IS THE VARIBALE WHICH IS USED TO STORE THE VALUE 90.

IDENTIFIERS:
IDENTIFIERS ARE BASICALLY USED TO IDENIFY THE VARIABLES. IF VARIABLE IS LIKE A CONTAINER,
THEN IDENTIFIERS ARE NOTHING BUT THE CONTAINER NAME.

IDENTIFIERS RULE:
1. THE VARIABLE NAME SHOULD NOT BE A KEYWORD
2. THE VARIABLE NAME SHOULD NOT CONTAIN ANY SPACE IN THE BEGINNING AND MIDDLE
FOR EXAMPLE:
a b= 30---→ we can not write the variable name in this way
3. THE VARIABLE NAME SHOULD NOT CONTAIN ANY NUMBER IN THE BEGINNING
FOR EXAMPLE:
2a=98----→ we cannot do this
4. THE VARIABLE NAME SHOULD NOT CONTAIN ANY SPECIAL CHARACTER EXCEPT _

WHAT WE CAN GIVE AS VARIABLE NAME:


[Link] COULD BE ALPHABET AND ALSO IT COULD BE ALPHANUMERIC

[Link] TO ISR RULE, IT SHOULD BE UPTO 79 CHARACTERS NOT MORE THAN THAT BUT EVEN
IF IT IS MORE THAN THAT IT WILL NOT THROW ANY ERROR.

DATATYPES:
Datatypes are basically used to specify the size and the type of data.

IN PYTHON WE HAVE 2 TYPES OF DATATYPES:

SINGLE VALUED DATATYPES:

WHEN WE ARE STORING ONE SINGLE VALUE INTO SINGLE VARIABLE

[Link] (real number without decimal value)

[Link] (real number with decimal value)

[Link] (combination of real and imaginary number)

[Link] (consist of two values: True and False)

MULTI VALUED DATATYPES:


WHEN WE ARE STORING MULTIPLE VALUES INSIDE ONE SINGLE VARIABLE

[Link] (str)

[Link]

[Link]

[Link]

[Link] (dict)

Now, to check the type of the data we can go for the inbuild function: type(var/value)

Again, to check the address of the variable or value we can go for the inbuild function that is:
id(var/value)

and also to check the inbuild functions for the multivalued datatypes, we have to use dir function

syntax to use dir: dir(datatype)

String(str):
String is basically combination of characters (uppercase, lowercase, numbers, special characters).

It should be enclosed within ‘ ‘ or “ “ or ‘’’ ‘’’’

a=’CREATIVE CHAMBER’

if I check type of a it will be str only.

List:
List is a collection of homogeneous and heterogeneous data items separated comma and
enclosed within []
a = [1,2,3,4] -----→homogeneous data items
a=[1,2,3,’hello’,’hi’,8.7] ---→heterogeneous data items
again, type(a)--→ will give list only

Tuple:
Tuple is a collection of homogeneous and heterogeneous data items separated comma and
enclosed within ()
a = (1,2,3,4) -----→homogeneous data items
a=(1,2,3,’hello’,’hi’,8.7) ---→heterogeneous data items
again, type(a)--→ will give tuple only

SET:
It is a collection of unordered and nonduplicate data items enclosed within {}
a = {1,2,3,4} -----→homogeneous data items
a={1,2,3,’hello’,’hi’,8.7} ---→heterogeneous data items
again, type(a)--→ will give set only
note: we can’t store mutable data items in set.

DICTIONARY:
It’s a combination of key-value pairs.
Syntax:
a= {K1:V1, K2:V2, K3:V3}
KEYS SHOULD BE UNIQUE AND IMMUTABLE.

INDEXING:
It is a phenomenon to extract some particular value from the given collection.
Syntax:
>>>Var[index]----→ it will give us the particular value which is present in that index
For example:
a= [1,2,3,4,5]
now to fetch the 4 value we have consider the indexing phenomenon.
>>>a[3] will give me the value 4.
Indexing is basically of 2 types:
[Link] Indexing (Starts from left) [0 to (len-1)]
[Link] Indexing (Starts from right) [-1 to -len]
NOTE: ONLY LIST AND STRING AND TUPLE SUPPORTS INDEXING
DICTIONARY USES KEY TO ACCESS SOME VALUE
EXAMPLE: d= {1:3,2:4,3:5} -----→ now to access the value 4, we will be using this syntax:
d[2].

MUTABLE AND IMMUTABLE DATATYPE:


Mutable datatypes are those datatypes which can be modified.
In python, only list, set and dictionary are considered as mutable datatypes.
To modify the list value:
Var[index]=new value
To modify dictionary:
Var[key]=new value
For set, we have some inbuild functions to do modifications as it doesn’t support indexing.
Immutable datatypes can not be modified. Except list, set and dictionary all single valued
datatypes and multi valued datatypes falls under the immutable datatypes.

SLICING:
It is a phenomenon of fetching some part of value sequentially from the collection.
Syntax:
Var [SI: EI±1: updation]
S=’PYTHON’
To reverse this string,
>>>S[::-1]
o/p: ‘NOHTYP’

OPERATORS:
Operators are basically used to perform some operation.
There are basically 7 types of operators:
[Link] Operators (+, -, *, /, //, %)
[Link] Operators (and, or, not)
[Link] Operators (>, <, ==, <=, >=)
[Link] operators (&, |, ~, ^, <<, >>)
[Link] operators: It is basically used to check whether the particular value is present
inside the collection or not.
Two keywords we have here---→ in and not in
[Link] Operators: It is basically used to check whether the both variables are pointing to
the same memory location or not.
Two keywords we have here--→ is and is not
[Link] operator

CONTROL STATEMENTS:
Control statements are basically used to control the flow of execution.
Two types of control statements we have in case of python:
1. Conditional statements
2. Looping statements

Conditional statements:
[Link] if:
Syntax:
If condition:

TSB

[Link]-else:
Syntax:
If condition:

TSB

Else:

FSB

[Link]:
If condition1:
Syntax:
TSB1

elif condition2:

TSB2

else:

FSB

[Link]-if:
Syntax: If condition:

If condition:

TSB

else:

FSB1

else:

FSB2
Looping Statements:
In order to perform same instruction n number of types we are going to consider looping
statements.
2 types of looping statements we have in python:
[Link] loop:
Initialization

while condition:

TSB

Updation

INTIALIZATION AND UPDATION IS MUST IN THE CASE OF WHILE LOOP.


While loop only supports indexing, that’s why it will not work for set and dictionary.
[Link] loop:

For var in collection:

SB

Here the collection can be any datatype including range().


NO NEED OF INITIALIZATION AND UPDATION.

Function:
Function is nothing but some block of code which is used to perform some specific
operation.
Functions are of 3 types:
[Link] function (These are common for each and every datatype)
Example: len(), id(), type()
[Link] Function
[Link] defined Function

USER DEFINED FUNCTION:


THESE ARE THE FUNCTIONS WHICH THE USER WILL BE CREATING BASED ON THEIR
REQUIREMENTS.
[Link] without arguments & without return value
[Link] with arguments & without return value
[Link] without arguments & with return value
[Link] with arguments & with return value

You might also like