Python Programming tutorial provides basic and advanced concepts of Python programming. This Python programming tutorial is designed for beginners and professionals. Python is a simple, general purpose, high level, and object-oriented programming language. In this we have different chapter and their concepts Python Programming : tokens, literals, identifiers, keywords, special symbols and operators; fundamental data types, expressions, type conversions, handling Input and output in Python. Selection Statements : if statement, if-else statement, if-elif-else statement, nested-if statement. Iterative Statements : while loop, for loop, break statement, continue statement, pass and else statements used with loops. Sequences : Lists and operations - creating, inserting elements, updating elements, deleting elements, searching and sorting, list comprehensions, nested lists; tuples - creating, searching and sorting, nested tuples; strings - Initializing a...
''' 1. Using generator we can execute a block of code based on demand by using next() function. 2. using yield keyword we can create a generator. ''' def gen_fun(n): for i in range(n): print('Before yield') yield i print('After yield') gen_obj = gen_fun(10) #print(next(gen_obj)) #print(next(gen_obj)) # print(next(gen_obj)) ## Iterate based on for loop #for i in gen_obj: # print(' For Loop ', i) def gen_fun(n): print('Before return') yield n print(' \n After return') yield n gen_obj = gen_fun(10) print(next(gen_obj)) print(next(gen_obj))
1. An exception is an event, which occurs during the execution of a program. 2. Using try,except,else and finally block we can handle exception. 3. Using exceptions we can handle run time errors. # else 1. else block will execute when the try block executed successfully with out any errors. # Finally *** 1. finally block will execute both times when try block executed successfully or fail. 2. It is used to do the cleanup process. 1) try and except import sys d = {'A':1,'B':2} try: d['C'] 'we' + '123' sys.ok() import re open('2_else.py') except ModuleNotFoundError: print(' Module is not defined ') except NameError: print(' name is not defined please define ') except KeyError: print(' KeyError ') except FileNotFoundError as e: print(' Please define file ', e) except: print(' Try block got failed ') 2)else block #''' #1. else block will ex...
Comments
Post a Comment