id int64 0 25.6k | text stringlengths 0 4.59k |
|---|---|
25,500 | unit-ivfile handling filestypes of filescreating and reading text datafile methods to read and write datareading and writing binary filesthe pickle modulereading and writing csv filespython os and os path modules filesa file is location on disk that stores related information and has name there are different kinds of f... |
25,501 | print( read() close( )read text file:read(method is used for reading the content in the file #creating demo txt file gedit demo txt python is interesting programming language #write python program to read data in demo txt =open('demo txt',' 'print( read() close(#read only part of filef=open('demo txt',' 'print( read( )... |
25,502 | #to view the content in the empty txt =open('empty txt',' 'print( read() close(outputi am writing data into the empty text file #write program to write data into existing file demo txt =open("demo txt",' ' write(" am overwriting the existing content" close(#to view the content in the demo txt =open("demo txt",' 'print(... |
25,503 | reading and writing of binary filesopening filefilepointer=open(filename,modefilename with extensionbinmodes"rbread opens binary file for reading "wbwrite opens binary file for writing /overwriting egf=open('demo bin','rb'#creating demo bin file gedit demo bin #write python program to read the data in demo bin file =op... |
25,504 | close(#to view the contents in demo bin =open('demo bin','rb'print( read() close(csv (comma separated valuefiles csv (comma-separated valuesis file containing text that is separated with comma,it is type of plain text that uses specific structuring to arrange tabular data csv files are used to handle large amount of da... |
25,505 | writerow([ , ,'aaa'] writerow([ , ,'bbb']#write the data into demo csv file import csv with open ("demo csv"," "as filef=csv writer(filef writerow([' no','rollno','name'] writerow([ , ,'aaa'] writerow([ , ,'bbb']the pickle module python pickle module is used for serializing and de-serializing python object structure an... |
25,506 | for in lprint('the data 'cis 'ic = outputshowing the pickled datathe data is the data is the data is note:for clear explanation refer to python os and os path modules it is possible to automatically perform many operating system tasks the os module in python provides functions for creating and removing directory (folde... |
25,507 | os rmdir("shanthi"output:shanthi directory on the desktop will be removed os path module in python this module contains some useful functions on pathnames os path basename(paththis function basically return the file name from the path given import os os path basename("shanthi/file "print(loutputfile os path dirname(pat... |
25,508 | uniti the information in main memory can be displayed through an output device inputis the process of entering data and instructions into the computer various input devices used are keyboardmousescannertrackball etc storageis the process of storing data and instructions in the computer computer has two types of storage... |
25,509 | uniti processingthe process of performing operations on the data as per the instructions specified by the user (programmain aim of this is to transform data into information data and instructions are taken from the primary memory and are transferred to the arithmetic and logic unitwhich performs all sorts of calculatio... |
25,510 | uniti it communicates with input/output devices for transfer of data or results from storage it does not process or store data arithmetic logical unit(alu)it performs arithmetic operations like additionsubtractionmultiplicationand division it performs logic operations such as comparingselectingmatchingand merging of da... |
25,511 | uniti secondary memory read-only memory (romromo stores information permanently in the computer its name is read-onlybecause computer can read but cannot write information in rom rom is non-volatile data stored in rom do not disappear when the computer is switched off secondary storage devices these devices are needed ... |
25,512 | uniti principle of abstractionabstraction is the process of trying to identify the most important or inherent qualities of an object or modeland ignoring or omitting the unimportant aspects (information hidingit consists of two partsdata and operations memory hierarchy memory hierarchy is the hierarchy of memory and st... |
25,513 | uniti cost capacity access time level- at level- registers are present which are contained inside the cpu since they are present inside the cputhey have least access time they are most expensive and therefore smallest in size (in kbregisters are implemented using flip-flops level- at level- cache memory is present it s... |
25,514 | uniti cost bit decreases frequency of access decreases capacity increases access time increases units of storage in computer computers are electronic machines which operate using binary logic these devices use two different values ( and to represent data this corresponding number system is referred as binary number sys... |
25,515 | uniti besides bytesdata is also specified using the units shown in the table circuits and logicthe basic digital electronic circuit that has one or more inputs and single output is known as logic gate logic gates are divided into three types they are basic gates:not,and,or universal gates :nand,nor arithmetic gates:exo... |
25,516 | uniti truth table for not and gateif both inputs are ' 'then only the outputy is ' for remaining combinations of inputsthe outputy is ' it is optional to represent the logical and with the symbol the following figure shows the symbol of an and gatewhich is having two inputs ab and one outputy the following table shows ... |
25,517 | uniti the following figure shows the symbol of an or gatewhich is having two inputs ab and one outputy the following table shows the truth table of -input or gate = + universal gates nand nor gates are called as universal gates because we can implement any boolean functionwhich is in sum of products form by using nand ... |
25,518 | uniti = ( ) nor gatenor gate is digital circuit that has two or more inputs and produces an outputwhich is the inversion of logical or of all those inputs the following figure shows the symbol of nor gatewhich is having two inputs ab and one outputy the following table shows the truth table of -input nor gate = + yi de... |
25,519 | uniti arithmetic gates:exor,exnor ex-or ex-nor gates are called as arithmetic gates becausethese two gates are special cases of or nor gates ex-or gate the full form of ex-or gate is exclusive-or gate if both the inputs are or both the inputs are ,then obtained output is and for the remaining cases the output is taken ... |
25,520 | uniti the following table shows the truth table of -input ex-nor gate ab advantages of logic gates logic gates are quick yet use low energy logic gates don' get overworked logic gates can lessen the prescribed number of / ports needed by microcontroller logic gates can bring about straightforward data encryption and de... |
25,521 | uniti managing allocation of memoryprocessor timeother resources for various tasks collecting input from the keyboardmouse and other input device sand providing this data to the currently running program conveying program output to the screenprinter or other output device accessing data from secondary storage writing d... |
25,522 | uniti representation of data in memory (integer (including negative)floating points etc to textimagesaudio and video)computer uses fixed number of bits to represent piece of datawhich could be numbera characteror others for examplea -bit memory location can hold one of these eight binary patterns or refer to units of s... |
25,523 | uniti negative signed binary numbers disadvantagesan unfortunate feature of sign-value representation is that there are two ways of representing the value zeroall bits set to zeroand all bits except the sign bit set to zero this makes the math bit confusing one' complement of signed binary number one' complement or ' c... |
25,524 | uniti disadvantagean unfortunate feature of one' complement representation is that there are two ways of representing the value zeroall bits set to zeroand all bits set to one two' complement of signed binary number two' complement or ' complement as it is also termedis another method like the previous sign-magnitude a... |
25,525 | uniti representing text when any key on keyboard is pressedit needs to be converted into binary number so that it can be processed by the computer and the typed character can appear on the screen department of csevishnu institute of technology |
25,526 | uniti code where each number represents character can be used to convert text into binary one code we can use for this is called ascii the ascii code takes each character on the keyboard and assigns it binary number for examplethe letter 'ahas the binary number (this is the denary number the letter 'bhas the binary num... |
25,527 | uniti adding colour the system described so far is fine for black and white imagesbut most images need to use colours as well instead of using just and using four possible numbers will allow an image to use four colours in binary this can be represented using two bits per pixel white blue green red while this is still ... |
25,528 | uniti the samples can then be converted to binary they will be recorded to the nearest whole number time sample denary binary language hierarchythere are generally three types of computer languages they are machine language assembly language and high-level languages machine language( 'sit is the lowest-level programmin... |
25,529 | uniti it consists of combination of ' and ' that represent high and low electrical voltage machine language is sequence of instructions written in the form of binary number to which computer responds directly it is considered as first generation language machine language instruction generally has three parts as shown b... |
25,530 | uniti the next evolution in programming came with the idea of replacing binary code for instruction and addresses with symbols or mnemonics because they used symbolsthese languages were first known as symbolic languages the set of these mnemonic languages were later referred to as assembly languages this language is al... |
25,531 | uniti improved readability than machine language less error prone when compared with machine language assembly programs can run can run much faster and use less memory and other resources more control on hardware disadvantagesmachine dependentit is specific to particular machine architecture hard to learn assembly lang... |
25,532 | uniti the program in high-level language is called the source program the translated program in machine language is called the object program two methods are used for translationcompilation and interpretation compilera compiler is translator which converts the program written in high-level language into assembly code o... |
25,533 | uniti error detection difficuilt easy examples , ++,java,scala,etc python,perl,php,ruby,etc command line interface the command line is text interface for your computer it' program that takes in commandswhich it passes on to the computer' operating system to run from the command lineyou can navigate through files and fo... |
25,534 | uniti basic windows cli commands linux commands pwd -when you first open the terminalyou are in the home directory of your user to know which directory you are inyou can use the "pwdcommand it gives us the absolute pathwhich means the path that starts from the root the root is the base of the linux file system it is de... |
25,535 | fixed part that is space required to store certain data and variables ( simple variables and constantsprogram size etc )that are not dependent of the size of the problem variable part is space required by variableswhose size is totally dependent on the size of the problem for examplerecursion stack spacedynamic memory ... |
25,536 | conditional and repetition blocks:check the flowcharts in the topic "control structures in python conditionals and loopscomputational thinkingit follows steps decompositiondivide the problem into smaller problemsusually problems that we have solved before pattern recognitionfind similar repeated patternsidentify the di... |
25,537 | step read variables , and step if > and >= assign to the largest elif >= and >= assign to the largest else assign to the largest step display largest step stop pseudo code )pseudo code is one of the method that is used to represent an algorithm )it is not written using specific rulesso it will not execute in computer )... |
25,538 | literal is raw data given in variable or constant in pythonthere are various types of literals they are as follows numeric literals string literals boolean literals literal collections numeric literals binary literals decimal literals octal literal hexadecimal literal float literal complex literal program to demonstrat... |
25,539 | print( boolean literalsa boolean literal can have any of the two valuestrue or false true false true false print(" is"xprint(" is"yprint(" :"aprint(" :"bliteral collections there are four different literal collections list literalstuple literalsdict literalsand set literals =[ , , =( , , ={ , , ={ :' ',' ':' 'print("li... |
25,540 | false class finally is return none continue for lambda try true def from nonlocal while and del global not with as elif if or yield assert else import pass break except in raise type conversion the process of converting the value of one data type (integerstringfloatetc to another data type is called type conversion pyt... |
25,541 | print("after explicit conversion",cprint(type( )outputbefore explicit conversion after explicit conversion variables variables are just names of memory locations variables are used to store and retrieve values from memory type of the variable is based on the value we assign to the variable variables are containers for ... |
25,542 | input():the input(function allows user to give input syntax input(promptpromptit can be empty or string ega=int(input() =float(input() =input( =int(input("enter the value of ")print('enter your name:' input(print('helloxx input('enter your name:'print('helloxmultiple input at timea, =input("enter firstname"),input("ent... |
25,543 | print('the value of is {and is {}format( , )outputthe value of is and is basic data types(numbers also includedevery value in python has datatype python has the following data types/objects built-in by defaultin these categoriestext typestr numeric typesintfloatcomplex sequence typeslisttuplerange mapping typedict set ... |
25,544 | = print(xprint(type( ) = print(yprint(type( ) =- print(zprint(type( )complex numberscomplex numbers in python are in the form of bj = + print(xprint(type( ) = print(yprint(type( ) =- print(zprint(type( )booleanspython provides boolean datatype called bool with values true false true represents integer and false represe... |
25,545 | " " ='pythonprint(aprint(type( ) =' print(bprint(type( ) =str(input("enter ")print(cprint(type( ) =input(print(dprint(type( )python operators operators are used to perform operations on variables and values python divides the operators in the following groupsarithmetic operators assignment operators comparison operator... |
25,546 | #arithmetic operators =int(input("enter the value of ") =int(input("enter the values of ")print("sum=", +yprint("sub=", -yprint("product=", *yprint("division", /yprint("modulus=", %yprint("exponentiation=", **yprint("floor division=", //yguest-guh cf@slave :~gedit arithmetic py guest-guh cf@slave :~python arithmetic py... |
25,547 | print( !=yprint( >yprint( <yprint( >=yprint( <=yguest-guh cf@slave :~gedit comparison py guest-guh cf@slave :~python comparison py enter the values of : enter the values of : false true false true false true python logical operators logical operators are used to combine conditional statements#logical operators =int(inp... |
25,548 | enter the value of : false false true python identity operators identity operators are used to compare the objectsnot if they are equalbut if they are actually the same objectwith the same memory location#identity operators =int(input("enter the value of :") =int(input("enter the value of :") = print( is yprint( is not... |
25,549 | =int(input("enter the value of :")print( in xprint( not in xguest-guh cf@slave :~gedit membership py guest-guh cf@slave :~python membership py enter the value of : true false python bitwise operators bitwise operators are used to compare (binarynumbers |
25,550 | =int(input("enter the value of :") =int(input("enter the value of :")print( &yprint( yprint( yprint(~xprint( << print( >> guest-guh cf@slave :~gedit bitwise py guest-guh cf@slave :~python bitwise py enter the value of : enter the value of : |
25,551 | - python assignment operators assignment operators are used to assign values to variableswrite program to demonstrate assignment operators =int(input("enter the value of :") + #same as = + print(" =",xx - #same as = - print(" =",xx * #same as = * print(" =",xx / #same as = / print(" =",xx % #same as = % print(" =",xx /... |
25,552 | enter the value of : expressions and order of evaluations(precedenceexpressionan expression is combination of operatorsconstants and variables an expression may consist of one or more operandsand zero or more operators to produce value eg * / * + python has well-defined rules for specifying the order in which the opera... |
25,553 | unary plusunary minusbitwise not *///multiplicationdivisionfloor divisionmodulus +additionsubtraction bitwise shift operators bitwise and bitwise xor bitwise or ==!=>>=<<=isis notinnot in comparisionsidentitymembership operators not logical not and logical and or logical or operator precedence rule in python egprint( p... |
25,554 | output print( * * shows the right-left associativity of *output print(( * * control structures in python conditionals and loops conditionalsdecision making statements/selection/conditional statements if statement if else statements elif ladder nested if statements if statement decision making is required when we want t... |
25,555 | num int(input("enter the value of num")if num print(num"is positive number "if else statement the if else statement evaluates test expression and will execute body of if only when test condition is true if the condition is falsebody of else is executed indentation is used to separate the blocks program checks if the nu... |
25,556 | if the condition for if is falseit checks the condition of the next elif block and so on if all the conditions are falsebody of else is executed #program on elif ladder num float(input("enter the value of num")if num print("positive number"elif num = print("zero"elseprint("negative number"python program to find the lar... |
25,557 | if cond statements elsestatements elseif cond statements elsestatements #program on nested if num float(input("enter number")if num > if num = print("zero"elseprint("positive number"elseprint("negative number"repetition statements(loops)for loop while loop for loop the for loop in python is used to iterate over sequenc... |
25,558 | hereval is the variable that takes the value of the item inside the sequence on each iteration loop continues until we reach the last item in the sequence the body of for loop is separated from the rest of the code using indentation egfor in range( )print(isyntax for rangerange(end# to end- range(start,end#start to end... |
25,559 | print("finally finished!"looping through string for in "ayaan"print(iwhile loop the while loop in python is used to iterate over block of code as long as the test expression (conditionis true flow chart eg#print numbers from to = while print(ii + #print odd numbers , , , , = while < print(ii= + #print even numbers , , ... |
25,560 | in pythonbreak and continue statements can alter the flow of normal loop loops iterate over block of code until test expression is falsebut sometimes we wish to terminate the current iteration or even the whole loop without checking test expression the break and continue statements are used in these cases python break ... |
25,561 | branch "csedef read_student_details(selfrnon)#regdno and name are instance variables self __regdno rno #regdno is private variable self name def print_student_details(self)print("student regd no is"self __regdnoprint("student name is"self nameprint("student branch is"student branchs student( read_student_details(" pa "... |
25,562 | def __del__(self)statement statement statementn for our student class__del__(method can be used as followsdef __del__(self)print("student object is being destroyed")other special methods method description __repr__(this method returns the string representation of an object it works on any objectnot just user class inst... |
25,563 | implementation of classwe can mark the method as private it is not recommended to access private method outside the class but if neededwe can access private method outside the class as followsobjectname _classname__privatemethod(arg arg if neededwe can access private variables using similar syntax as above following ex... |
25,564 | description __dict__ gives the dictionary containing the namespace of class __doc__ gives the documentation string of the class if specified otherwiseit returns none __name__ gives the name of the class __module__ gives the name of the module in which the class is defined __bases__ gives the base classes in inheritance... |
25,565 | and cls following example demonstrates static methodclass boxsides none def __init__(selflb)self length self breadth def display(self)print("length of box is:"self lengthprint("breadth of box is:"self breadth@staticmethod def init_sides( )sides print("sides of box ="sidesbox init_sides( box( , display(inheritance creat... |
25,566 | following example demonstrates inheritance in pythonclass shapedef __init__(self)print("shape constructor"def area()print("area of shape"def peri()print("perimeter of shape"class circle(shape)def __init__(selfr)shape __init__(self#calling parent constructor self radius print("circle constructor"def area(self)print("are... |
25,567 | introduction an error is an abnormal condition that results in unexpected behavior of program common kinds of errors are syntax errors and logical errors syntax errors arise due to poor understanding of the language logical errors arise due to poor understanding of the problem and its solution anomalies that occur at r... |
25,568 | exceptions are placed in try block code that handles the exception is placed in except block the code that handles an exception is known as exception handler and this process is known as exception handling try and except syntax for using try and except for exception handling is as followstrystatement(sexcept exceptionn... |
25,569 | outputquotient multiple except blocks oftenthere will be need to handle more than one exception raised by try block to handle multiple exceptionswe can write multiple except blocks as shown belowtrystatement(sexcept exceptionname statement(sexcept exceptionname statement(sfollowing is an example for handling multiple e... |
25,570 | denominator int(input()tryquotient numerator denominator print("quotient:"quotientexcept (nameerror,valueerror,zerodivisionerror)print("denominator cannot be zero"for input and the output for the above code isdenominator cannot be zero handle any exception in some caseswe might want to execute the same code (handlerfor... |
25,571 | exceptionname is the type of exception we want to raise args are the exception arguments and traceback is the traceback object used for the exception following is an example for demonstrating raise keywordtryraise nameerror except nameerrorprint("name error"in the above code nameerror exception is raised by the raise s... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.