CLASS XIIA ONLINE CLASSES BY R.K.YADAV PGT-CS
PYTHON LEARNING BY RK YADAV KV RDSO LUCKNOW:-
TODAY CLASS AS ON :- 06-05-2020
JUST OPEN LINK FOR NOTES Python Library
PDF LINK FOR 06-05-2020
CLASS ON :- 28-04-2020
call the function as below.
Q1:- >>>chr(65)
>>>ord("a")
>>>ord("a")
Q2. A= "HELLOINDIA"
B= len(a)
print(B)
Q3:- range(10)
range(1,5)
range(1,10,2)
Q4:-X= 15.12345
print("%f,%2f"%(X,X))
Q5:-def fun(s):
k = len(s)
m= ""
for i in range(0,k):
ifs[i].upper()
m = m +s[i].lower()
elif s[i].lower():
m= m+s[i].upper()
else:
m= m+"bb""
print(m)
run the programe
fun("school2@com")
TODAY CLASS AS ON :- 06-05-2020
JUST OPEN LINK FOR NOTES Python Library
PDF LINK FOR 06-05-2020
PDF LINK FOR 30-04-2020 CLASS
PDF LINK FOR 05-05-2020 CLASS
Introduction:
PDF LINK FOR 05-05-2020 CLASS
Introduction:
A library is a place where lots of books, magazines, CDs, newspapers are found to read. These all books are divided into several chapters, magazines are divided into several articles
Definition:
A library is a collection of modules or functions in a python that allows to do a specific tasks to fulfill user's need. This library serves little bit similar functions as header files used in C or C++. Some commonly used python libraries are as following:
- Standard Library: It provides some common standard IO operation related functions such as print(), input(), int() along with some math modules, random modules, statistic modules etc.
- NumPy Library: This library is used to handle arrays to cater basic mathematical operations. Ex.: square(), absoulte(), log(), sqrt() etc.
- SciPY Library: This offers algorithmic and mathematical functions for scientific calculations. Ex.: io(), linalg(), interopolate() etc
- Matplotlib Library: This library offers functions related to graphs and charts in python. Ex.: plot(), label(), show() etc
- Tkinter Library: This library provides functions to design GUI based interface for different applications. Ex.: tkMessageBox(), tkColorChooser(), tkSimpleDialog() etc.
- import <command> : import math, import numpy etc
- from <module> import <object>: from math import pi, sqrt
To use mathematical function import math object by using import:
import math
The following functions are most commonly used functions provided by math module:
- ceil():Return the smallest integer greater than or equal to the number specified.
Ex.: >>> math.ceil(12345.6786)
Output:12346 - fabs():Return the absolute value of given number. Convert and display negative number into positive number.
Ex.: >>> math.fabs(-15)
Output:15.0 - factorial():Return the factorial of given number. If the number is integral or negative then it returns ValueError.
Ex.: >>> math.faactorial(5)
Output:120 - floor():Return the largest integer less than or equal to the number specified.
Ex.: >>> math.floor(12345.6786)
Output:1234 - fmod():Return the remainder working with float values only. For integer use % operator.
Ex.: >>> math.fmod(15.8899,4)
Output:3.889900000000001 - fsum():Return addition of values in iterable.
Ex.: >>> math.fsum([1.5,2.5,3.5])
Output:7.5 - gcd():Return common divisor of the specified numbers x and y.
Ex.: >>> math.gcd(42,28)
Output:14 - remainder():Return remainder of integer with number x divided by y.
Ex.: >>> math.remainder(12,5)
Output:2.0 - pow():Return power of x raised by y.
Ex.: >>> math.pow(5,3)
Output:125.0 - sqrt():Return square root of given number.
Ex.: >>> math.sqrt(100)
Output:10.0
- To use string functions a variable needs to assign with specific string value.For Ex.: str ="fun with python"
- capitalize(): Convert first letter of the text into capital. Ex.: >>> str.capitalize()
- center(): It align the string to center by filling padding the character left and right of the string.
Ex.: >>> str2=str.center(20,'*')
Output:'**fun with python***' - count():Return no. occurrences of specified string.
Ex.: >>> str.count('with',4,10)
Output:1 - endswith():Return True if the specified text ends with given string, otherwise False. stratswith() method is opposite of endswith.
Ex.: >>> str.endswith('on',0,20)
Output:True - find():Return lowest index in the string where substring sub is found, such that sub is contained in the range. Returns -1 if substring is not found the text.
Ex.: >>> str.find('with',4,10)
Output:4 - isalnum():Return True if all characters in the string are alphnumerical otherwise False. It requires at least 1 character.
Ex.: >>> str='funwithpython2020'
>>> str.isalnum()
Output: True
Similarly isalpha(), isdigit(), islower(), isspace(), istitle, isupper() functions return True respectively, otherwise false.
- join():Concate string specified as in sequence.
Ex.: >>>str='fun with python 2020'
>>> str.join(['hello! ',' is amazing')
Output: 'hello! fun with python 2020 is amazing' - upper(): Convert all text into capital letters. Ex.: >>> str.upper()
- title(): Convert first letter of each word into capitals. Ex.: >>> str.title()
- swapcase(): Convert capital letters into small letters and small letters to capital letters. Ex.: >>> str.swapcase()
- split(): Split the the words by given characters. If number is specified as maxsplit then it returns n+1 string as output. Ex.: >>> str.split(' ')
- ljust(): Return the string in left justified in a string of up to the length of string. The string is filled up with a specified character. rjust() is just opposite of ljust(). Ex.: >>> str.ljust(25,'*')
- lower(): Convert the specified text into lowercase. Ex.: >>> str.lower()
- lstrip(): Removes the specified characters from the string from leading text. rstrip() is just opposite of lstrip().
- replace(): Replace the new text with old text.
Output:'Fun with python'
Output:'FUN WITH PYTHON 2020'
Output:'Fun With Python 2020'
Output:'FUN WITH PYTHON 2020'
Output:['fun','with','python','2020']
Output:'fun with python 2020******'
Output:'fun with python 2020- Ex.: >>> str.lstrip('ufp')
Output:'n with python 2020'- Ex.: >>> str.replace('fun','play')
Output:'play with python 2020'
CLASS ON :- 28-04-2020
JUST OPEN LINK FOR NOTES
Today class 09-04-2020
Python Functions EXAMPLE :-
- WRITE A FUNCTION TO PRINT SUM OF THREE SUBJECT MARKS,USE PYTHON CODE?
- WRITE A FUNCTION TO PRINT FIBO SERIES OF ANY NUMBER,USE PYTHON CODE ONLY ?
- WRITE A FUNCTION TO PRINT FACTORIAL NUMBER USE PYTHON CODE ONLY ?
- WRITE A FUNCTION TO PRINT THE TABLE OF ANY GIVEN NUMBER USE PYTHON CODE?
- WRITE A FUNCTION TO FILTER THE LIST OF EVEN NUMBER USE PYTHON CODE ONLY ? EXAMPLE:-
RESULT
L = [2.4.6.8.10]
Note :- All above do in copy as well as computer system .
You can define any function as you want ,
Solution question no-2
def fibo(n):
a=0
b=1
print(a)
print(b)
for i in range(0,n-1):
c=a+b
print(c)
a=b
b=c
run its output are like as
>>>
RESTART: C:/Users/RajKumar/AppData/Local/Programs/Python/Python37-32/fibo.py
>>> fibo(5)
0
1
1
2
3
5
>>>
Today class 08-04-2020
Python Functions:-
A function is a user define block of code which only runs when it is called.
You can pass data, known as parameters, into a function.
A function can return data as a result.
Creating a Function
In Python a function is defined using the def keyword:
Example:-
def my_function():
print("Hello ,i am studying class XIIA student")
print("Hello ,i am studying class XIIA student")
print("Have a nice day")
call the function as below.
>>>my_function()
Hello ,i am studying class XIIA student
Have a nice day
ACTIVITY FIND OUTPUT:-
>>>ord("a")
>>>ord("a")
Q2. A= "HELLOINDIA"
B= len(a)
print(B)
Q3:- range(10)
range(1,5)
range(1,10,2)
Q4:-X= 15.12345
print("%f,%2f"%(X,X))
Q5:-def fun(s):
k = len(s)
m= ""
for i in range(0,k):
ifs[i].upper()
m = m +s[i].lower()
elif s[i].lower():
m= m+s[i].upper()
else:
m= m+"bb""
print(m)
run the programe
fun("school2@com")
Comments
Post a Comment