''' 1. Using sys module we can do system related operation. ''' import sys print(sys.version) ## to append path #sys.path.append(r'C:\\Users\\sriram\\Desktop\\akr') ## To exit from execution print(' \n Before exit') sys.exit() print(' \n After exit') -------------Input and Output using sys The sys modules provide variables for better control over input or output. We can even redirect the input and output to other devices. This can be done using three variables – 1.stdin 2.stdout 3.stderr ----stdin---: It can be used to get input from the command line directly. It used is for standard input. It internally calls the input() method. It, also, automatically adds ‘\n’ after each sentence. import sys for line in sys.stdin: if 'q' == line.rstrip(): break print(f'Input : {line}') print("Exit") --------stdout-------: A built-in file object that is to the interpreter’s standard out...
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. 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