Posts

Showing posts from April, 2025

Python_Functions

def function_display_details(person_name, number): a = 1 while (a <= number): print(f"Hello, {person_name}") a = a + 1 else: print(f"I have printed {person_name} {number} times") function_display_details("Tvisha", 2) function_display_details("Tejasvi", 3) function_display_details("Damodar", 4) function_display_details("Vijaya", 5) #______________________________________________________________________________________________________________________ #Ex: Write a function to 1. display number as long as it is less than value of 10. 2. Use the While loop and without any built-in functions like range(). 3. Write the numbers in the format - 1, 2, 3, 4, 5, 6, 7, 8, 9,10 def display_number(number): a = 1 while (a <= number): print(a, end+",") a = a + 1 else: print("Loop completed") display_number(10): _________________________________...

Python_Lists

  List Data Structure: ================= Creation of list ----------------------- 1). l = [ ] -- Blank List 2). l = [10,20,30,40] 3).with dynamic list ------------------------------- l = eval(input('Enter List:')) print(type(l)) 4).with list() function -------------------------------- l = list(range(10)) print(l) 5).with split() function ---------------------------------- s = 'python is very easy' l = s.split() print(l) Accessing elements of list: ---------------------------------------- 1).By using index: l = [10,20,30,40] l[0] #10 l[-1] #40 l[10] #IndexError 2).By using slice operator: n = [1,2,3,4,5,6,7,8,9,10] n[2:7:2]#[3,5,7] n[4::2]#[5,7,9] n[3:7]#[4,5,6,7] n[8:2:-2]#[9,7,5] n[4:100]#[5,6,7,8,9,10] List vs Mutability: --------------------------- -->Once we create a list object, we can modify its content. Hence list objects are mutable. Ex: n = [10,20,30,40] print(n) n[1] = 333 print(n)#[10,333,30,40] Traversing the elements ...

Python_Strings

  String Data Type =============== What is a string? Any sequence of characters within either single or double or triple quotes is considered as a string. Ex: s = 'sunny' s = "sunny" s = '''sunny''' s = """sunny""" How to define multiline string: ----------------------------------------------- s = '''Naresh It Technologies''' print(s) Ex: ----- 'This is a ' single code symbol' #invalid "This is a ' single code symbol" #Valid 'This is a \' single code symbol' #Valid How to access characters of a string: ------------------------------------------------------- 1).By using index: -->Python supports both +ve and -ve index. -->+ve index means left to right(forward direction) -->-ve index means right to left(backward direction) Ex: s = 'sunny' s[0] #s s[-1]#y s[10]#IndexError Q.w.a.p to accept som...

Python_DataTypes

Data Types Declaration: ________________________ 1.Static DT: ------------------ -->In static type programming languages programmer should define the data type to the variable explicitly. Ex: int x; float f; string s; -->In static DT supported languages, one variable can store only one veraity of data. -->C,C++,Java,.Net...........languages supports static data types. 2.Dynamic DT: ----------------------- -->In dynamic data type supported languages, programmer should not define the data types to the variables explicitly. -->At the time of execution of program, data type of variable is decided based on the data which we assign to the variable. Ex: x = 10-->int y = 1.2-->float z = '10'-->str -->Python and JavaScript.....languages are supported dynamic data types. Python data types: ---------------------------- 1.Fundamental data types: int,float,bool,str, complex 2.Collection data types: list,tuple,r...

Pyhon_Patterns

Ascending incremental Patterns: ------------------------------- # Write a program to print the following pattern. assume the number of rows is 5. 1. Use the While Loop 2. Use the Nested While Loop 3. Use For Loop 4. Use Nested For loop * * * * * * * * * * * * * * * Solution: number= int(input('Enter no of rows:'))#5 print('Using While Loop') print('________________________') a=0 while a<=number: print('*'*a) a=a+1 print('Using Nested While Loop') print('________________________') a=0 while a<=number: b=0 while b<=a: print('*', end='') b = b +1 print() a=a+1 print('Using For Loop') print('________________________') for a in range(number+1): print(a*'*') print('Using Nested For Loop') print('________________________') for a in range(number+1): for b in range (a): print('*', end='') print() #___________________________...