0% found this document useful (0 votes)
76 views

Computer science PYTHON book pdf for class 12

sumita arora class 12 2024-25 computer science pdf

Uploaded by

vedantvaidya08
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
76 views

Computer science PYTHON book pdf for class 12

sumita arora class 12 2024-25 computer science pdf

Uploaded by

vedantvaidya08
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 325
COMPUTER SCIENCE i ython | Textbook for Class XII * Programming & Computational Thinking * Computer Networks + Data Management (SQL, Django) * Society, Law and Ethics SUMITA ARORA hy 2 - DHANPAT RAI & Co, www.worldvideweb.com Preface Quality of education depends a lot on the curriculum imparted. Since Computer Science is a rapidly evolving field, CBSE constituted a committee to look Into existing Computer Science curriculum and Fecommend a curriculum that is modern, relatively light, teaches timeless concepts like computational thinking, is upto international standards and focuses on problem solving skills than [ust the syntax. The new syllabus of Computer Science (083) Is the outcome of the recommendations by the curriculum review committee. The objectives of this new syllabus are laudable — focus on clear understanding of concepts, applications of concepts, problem solving skills, develop computational thinking etc. This book has been written keeping all this in mind. This book adheres to the CBSE curriculum for Computer Science (083) for Class XI. Based of the syllabus, the book has been divided into four units. Unit 1: Programming and Computational Thinking (PCT-2) Unit 1 has been divided into ten chapters (chapters 1-10). It covers Python programming through fevision tour, Python functions, Libraries, File handling in Python, Recursion in Python functions, Data visualization using PyPlot, Data Structures in Python. This unit also covers basics of determining algorithm efficiency. Unit 2 : Computer Networks (CN) This unit has been divided into two chapters (chapters 11-12). It cavers computer networks’ basics such as types of networks, cloud technology, loT, wired and wireless networks, client, server networks, network devices, modulation techniques, collision in wireless networks, IPv4, IPVG, TCP, other protacals and network tools. Unit 3: Dato Management (DM-2) This unit has been divided into four chapters (chapters 13-16). It covers SQL revision, more on SQL commands, developing a minimal web application using Django web framework, and Python database connectivity with MySQL databases. Unit 4 : Society, Law and Ethics (SLE-2) This unit has been covered in one chapter (chapter 17). It covers many topics and issues related to society, law and ethies, such as 1PR, plagiarism, digital rights and licencing, privacy laws and cyber crime, I act, e-waste management, challenges online and gender and disability issues. Apart from the text book, we have also provided a practical book ‘Progress In Python’ that contains Additional practice exercises, Although the text book contains sufficient number of practice questions ‘and exercises, yet the additional practice of exercises given in the practical book will make the foundation of programming and other concepts even stranger. www.worldvideweb.com Syllabus Distribution of Marks ‘Unit No. Unit Name Marks A Programming and Computational Thinking 2 % 2 Computer Networks 1S 3 Data Management=2 15 : Society, Law and Ethics—2 10 5. Practicals 30 100 Total Unit 1 : Programming ond Computational Thinking (PCT-2) (80 Theory + 70 Practical) 4 Revision of the basies of Python 4 Functions: scope, parameter passing, mutableimmutable properties of data objects, pass arrays to functions, return values, functions using libraries: mathematical, and string functions. ¢+ File handling: open and close a file, read, write, and append toa file, standard input, output and error streams, relative and absolute paths. Using Python libraries: create and import Python libraries 4 Recursion: simple algorithms with recursion: factorial, Fibonacci numbe search, 4 Idea of efficiency: performance defined as inversely proportional to the wall clock time, count the number of operalionsa piece of codeis performing, and meastire the time taken by a program, Example: problem, and understand! how the efficient one takes less time, jecursion on arrays: binary take two different programs for the sar lot: Line chart, pie chart, and bar chart, 4 Data visualization using P 4 Datasstructures: lists, stacks, que Unit 2: Computer Networks (CN) (30 Theory + 10 Practical) + Structure of a network : Types of networks: local area andl wide area (web and intemet), nev technologies such as cloud and lol, public vs private cloud, wired and wireless networks; concept ofa client and server. 4 Network devices such asa NIC, switch, hub, route 4 Network stack: amplitude and frequency modulation, collision in wireless networks, error checking and the notion uf a MAC address, main idea of routing. IP addresses: (v4 and v6), routing table, rouler DNS od wth UBles TCT : basic idea of retransmission, and rate modulation when there iS cont y oad netw tacols: 2 iF " ve a hi {analogy to 2 road network), Protocols: 2G, 3G, 4G, WiFL. What makes a protocol have 2 ? Basi neti tools: traceroute, ping, ipconfig, nslookup, whois, speed-test. 4 Seen ibe HTTP (basic idea), working of email, secure communication : encryplion ef ates (HTTPS), network applications: remote desktop, remote login, HTTP, FTP, SCT 9°" « POPAMAP, SMTP, VolP, NFC. a vi B and access point. www.worldvideweb.com Unit 3: Data Management (DM-2) (20 Theory + 20 Practical) * Write a minimal Django bo and writes the ne BO based web: Mication that parses a GET and POST request, wt elds to a file- Mat file and CSV file et " > Interface , Python with om SQL database, * SQ commands: aggregation unctions having, group by, order by. Unit 4: Society, Law and Ethics (SLe-2) a Se (10 Theory) atellectual property rights, pla i , ly &, Plagiarism, digital rights management, and licensing (Creative Commons, Gotan Auch en we onde pe EM eg + Privacy laws, raud; cyber-crime, i ‘ i rane oe & “ i Cybercrime, phishing, illegal downloads, child Pomography, scams; cyber Technology and society: 2 = nology and society understanding of Societal issues and cultural changes induced by technology. waste management : proper disposal of used electronic gadgets. % Identity theft, unique ids, and biometrics, * Gender and disability ‘ssues while teaching and using computers, PRACTICAL Unit No. Unit Name Marks 1 Lab Test (10 marks) Exthon program (60% logie + 20% documentation + 20% code quality) 7 Small Python program that sends a SQL query to a databsse and 3 displays the result. A stub program ean be provided 2 Report File + Viva (9 marks) Revert file: Minimum 21 Python programs. Out of this at least 4 7 Programs should send SQL commands to a database and retrieve the result; at least I program should implement the web server to write user data to a CSY file, View voce : (based on the report file) 93 3. Project + Viva (11 marks) Project (that uses most of the concepts that have been learnt) 8 Project viva voee 3 Programming in Python 4% Recursively find the factorial of a natural number, Read a file fine by line and print it. 4 Remove all the lines that contain the character ‘a’ in a file and write it to another file, 4 Writea Python function sin (x, n) to calculate the value of sin (x) using its Taylor series expansion up tot terms. Compare the values of sin (x) for different values of 11 with the correct value, + Writea random number or that generates random numbers between 1 and 6 (simulates a dice), + Write a recursive code to find the sum of all elements of a list. + Write a recursive code to compute the 1 Fibonacci number, 4 Write a Python program to implement a stack and queue using a list data-structure, 4 Write a recursive Python program to test if a string is a palindrome or not. vii aa ta plot the function y = * using the pyplot or matplotiib libraries, mi to vrite a Python prone at secepts user inputs, performs some aperation on them, Fee graphical appucation that sromaple, write a small calculator. Use the tkinter ig 84 then Create f Bit pul bn the screen. For © “ weiter OY ian the urllib hbrary. = oe 2 ope error a Joanusing the numpy oF PY — Comput EA io phishing emails and find the most common wor $ Takea sample o + SQL ond Web-Server Delo Managemen! aon ‘and average of the marks in a student marks table + Find the min, m2) . try in the table (customer ID, Sir he tou! number of customers from each country Customer nam eee Oe the (student ID, marks) table in descending order of the marks. ane importing the MySQL module. vith Python by i _ 3 igo a est (POST), and write it to a CSV file, er to parse a user reques ) : 4 Wrte a Django based web server sie something that is tangible and useful. This should be done in i oject is to create Bsa fateaitedoe and should be started by students at least 6 months before the submission groups of 2 to to solve. Students are im here is to find a real world problem that is worthiwhil See foal Mites Gadel ther about the problems that they are facing. Far example, ila business is finding it hard toereate invoices for filing GST elaims, then students can do.a project ta; takes the raw data (list of Iransactions), groups the transactions by category, accounts for the GST tax rates and creates invoiees in the appropriate format, Students can be extremely creative here. They can use a wide variely of Python libraries to ereate user friendly applications such as games, software for and mobile applications. Of caurse to dosome their school, software for their disabled fellow shudent: of this projects some additional leaming is required; this should be encouraged. Students should know how to teach themselves Ifthree people work on a project for 6 months, at least 500 lines af code is expected. The committee has also been made aware about the degree of plagiarism in stich projects. Teachers should take a very strict Jook at this situation, and take very strict disciplinary action against students who are cheating on lib asignments, or projects, oF using pirated software to do the Everything that is proposed ean be achieved using absolutely free, and legitimate open source 7 www.worldvideweb.com www.worldvideweb.com Contents 1 Python Revision ‘Tour 11 Introduction 12 Tokens in Python 121 Keyuveds 2 122 Mentifers (Names) 2 123 LiterateVatues 3 Operators 125 Punctsors 4 13 Barebones of a Python Program 1A. Variablesand Assignments LAI Dynanie Tying 6 142 Multple Assignrents ¢ 15. Simple tnput and Output 1.6 Data Types 17 Mutableand immutabteTypes 1.8 Expressions: 18.1 Eeulusting Arithmetic Operations: 13 18.2 Enchuating Relatonet Expressions 183 Eeulusteng Logical Expressions 1) 184 Tape Casting (Lapltet Type Corsvrsion) 16 185 Muti Library Functions. 16 1.9 Statement Flow Controt 1.10 TheifConditionals 1.10.10 if Cotton Staterzent 19 1.10.2The ifese Comitorsl Stator 20 1.10.3The ssf Conta! Statement 20 110A Nested if Stalerents 1.10 5Storing Condition 141 Looping Statements LILA The for Loy 23 1AL2 The white Loop 2 1.12. Jump Statements break and continue The break Statement 25 The continue Statement 26 1,13 MoreonLoops LAB. Lavp elie Statement 27 1132 Neste Lops 28 a 10 2 4 18 19 2 a a python Revision Tour-II ‘21 Introduction = inython ” irings! , 22 set mS 222 Traversing a String 3 1223 Siring Operators 3S 224 Siring Slices 4 225 siring Functions 42 23 Listsin Python 331 Creating Lists 46 232 Lasis rs Sirings 47 parted 38 233 List Operations 48 2.34 List Manipulation 50 ofa List 51 235 Making True Cory 236 List Functions ST 24 Tuplesin Python 2A Creahing 24.2 Tuples rs Lists 56 243 Tuple Operations 57 244 Tuple Functions and Methods: 59 25. Dictionaries in Python 251 Creating a Dictionary 61 252 Accessing Elements of a Dictomary. 67 253 Characteristics of « Dictionary 254 Dictionary Ope 255 Dictionary Functions and Methats. 65 2.6 Sorting Techniques 26.1 Buble Sort 70 262 Insertion Sort 71 res 55 3 |) Working with Functions 85-140 31 Introduction 32. Understanding Functions 321 Calin 32. 33 Defi ‘wihing/Using a Function 87 2 Python Function Tyres. 85 ning Functions in Python et Structure of a Python Program 9} ow of Execution ina Function Cal} ments ond Parameters. 96 rameters 551 Pestonat Renn quired Atgunsent, 352 Delt Arguments 9g 8 353 Keyed ( 34 35 Passing Pa 55 6 0 85 86 ® Returning Values From Functions 3ST Returning Multiple Valucy 105 37 Composition 3.8 Scope uf Variables S41 Neme Rewlution (Reaeing Scope of a Name) N12 3.9 Mutable/tmmut: able Properties OF Passed Data Objects JT Mtutatuhty tm 4 Using Python Li Wl -172 ily of Arguments Parameters and Funct Calls 7 praries 41 Amroduetion 42 Whatisatitrary? %S 43. Importing Modes ina Python Program 441 Importing Ente Malate 1 432 beprting Set Offs froma Module 7 $3.3. Pethon’s Preessing of inguit anal 44 Using Python Standard Lib rman 17 y's Functions and Modules Python’ Busitn Functions 442 Working sath Some Stand 45 Creatinga Python Libran 451 Strncture fat in Library Matus 19% age tet 452 Preesture for Creating Packages Io 45.3 Using importing Pyth Libraries 2 le Handling ’ 173-200 5.1. Introduction . 52 DataFiles 53. Opening and Closing Files “ SY Opening Files 1 SAI Ching Iv 1 5A. Readingand Writing Fites 54.1 Reading from Fite S42 Writing onto Files 189 SA} The flash) Function 187 BA Removing Whitespace after Reading from File 18; SAS Significance of File Poanter 1 File Handling 139 Standard Input, Output and E 6 Recursion 6:1 troduction aes 62 Recursive Function 63 Hove Recursion Works fe Recursion in ython fal) Some Rear Cal 215 642 Binary Serch 218 43 Reswiee Bray Seach 222 65 Recursion lteration | | 102 107 107 “41 142 5 173 174 174 v7 190 201 202 205 212 223 7 233 - 250 8 251 - 295 9 297 ~ 332 Idea of Algorithmic Efficiency 7.1 Introduction 72. What ls Computational Complexity ? 73 Estimating Complexity of Algorithms 73.1 Big-O Notatin 234 7.32 Guidelines for Computing Complerity 236 7A_ Best, Average and Worst Case Complexity "Data Visualization using Pyplot 8.1 Whats Data VISUALIZATION? 82. Using Pyplot of Matplotlib Library S21 Instelleng and Importing matplotlih: 2 8.22 Working with PyPlot Metfids 253 83 Creating Charts with matplothb Library's pyplot Interface 84.1 Line Chart 259 $32 Rar Chart 265 843 The Pie Chant 275 84 Customizing the Plot 84.1 Anatomy ofa Chart 250 $42 Adting a Tite 231 843 Setting X and ¥ Labels, Limits and Ticks 287 BAA Adting Legends 285 $45 Socmng a Figure 257 85 ComparingChart Types Data Structures - 1: Lin 9.1 Introduction 92 93 ear Lists Elementary Data Representation Different Data Structures DAT Lincar bs 93.2 Stacks 299 933 Queues 299 934 Linked Lists 209 935 Trees 300 94 Operations on Data Structures 95 LnearLists 9.6 Linear List Data Structure Arrays 239 96.1 Searching ina Linear List 302 26.2 Insertion im a Linear Lis! 304 283 Deletion ofan Element fm a Sorted Linesr List 30 9.64 Traversal of a Lincar List 310 9.65 Sorting a Linear List 311 9.6.6 List Compretiensions 314 97 Nested /Two Dimensional Listsin Python 9.2.1 Tuo Dimensional Lists 320 a+ 233 234 234 239 281 252 259 200 288 297 297 298 300 300 300 319 10 Data Structures ~ I1: Stacks and Queues 333-368-1041 Introduction 102 Stacks 10.2.1. Implementing Stack in Python 336 1022 Stack Apptications 339 10.3 Queues 103.1 Implementing Quewesin Python 349 1032 Variations im Quewes 352 103.3 Queue Applications 353 11 Computer Networks — 369-386 LI Introduction 11.2 Computer Networks - An Introduction M21 Compnents ofa Computer Network 371 \ 11.3 Types of Networks TIAL Types of Netaorts ued on Geographical Spread 372 M32 Typeset Netavris by Component Rots 374 IBS Tye of Netaveis bel on Communication Channel 375 14 Network Devices/Hardware TAT NIC (Netzvrk Interface Cart) 377 42 WiFi Cant 7 143 Hub 375 nad AS Bindge 379 M46 Router 379 TAT Gateway 379 h ATS MAS Acces Point 179 MS The Cloud IS. Types of Clowls 18 116 Internetof Things (LoT) 116.1 Enabling Technologies for LOT 3S; 11.6.2 Devices that cam form [oT 382 1163 Challenges and Risks 153 12 | Computer Networks - IT 387-430 12.1 Introduction 12.2 Modulation Techniques 122.1 Major Types of Mxtulation 388 13 Collision in Wireless Networks 3.1 Hoa CSMAICA Works 391 124 Error Checking (Error Detection) 125 Main Idea of Routing 126 TCP/IP 126.1 Network Congestion and Retransmission in TCP 402 a aii ey 333 334 347 369 370 372 377 381 387 308 390 393 398 401 13 431 - 456 127 Addresseson a Network 127.1 The Domain Name and DNS 408 128 Cellular/Wireless Connectivity Protocols 129 Basic Network Tools 1281 FING 408 1292 TRACEROUTE ifr Linus) or TRACERT (for Wind) 4ir9 1295 NSLOOKUP 407 1294 INONFIG Comment 410 1295 WHOIS Commend 411 1296. Spend Tot at 12.10 Various Protocols Used on Networks 1211 How HTTP Works - A Basic Idea 1212 Working of Email I2I3_ Secure Communication Ane MTTPs air 2 Secure Seles Layer (SSL) 417 1214 Network Applications MySQL SQL Revision Tour 131 Introduction 132, Relational Data Model 133. MySQL-A popular Relational DataBase Management Syst INST MySQL ene SOL sit IN32 Commer MySQL Data Tyres 4 134 Accessing Database in MySQL 135 Creating Tables in MySQL. 136 Inserting Data into Table 137 Making Simple Queries Through Setect Command Seating AME Sctevting Pertcutar Kes 4 lar Cedar 4 Sdeving P Liminating Retertant Data (with beyaved DISTINCD Seeting From All the Roser ~ ALL Reyne 417 Virsang Stracture fe Table 47 Perhorreing Simpte C tomy $8 Ung Coluren Aliser 619 Conditun Based ona Range 438 13720 Conattaon Based om a List $3 INT AT Covtitim awd on Pattern Matches 435 wr, ULL 439 13.8 Creating Tables with SQL Constraints IST SQL Comatracats 440 INS2 Applying Table Constraints 44 Le Searching be 436 40 139 Viewing a Table Structure B40 Inserting Data into Another Table 13.11 Modifying Datain Tables 1312 Deleting Data from Tables 13.13 Altering Tables 13.4 Dropping Tables 13.45. sqLjoins 13.6 Indexes in Database 14 More on sau. AT -AT yy Introduction V2 Ordering Records in Result -Order| ‘by Clause N21 Resting SQL Sct Onder fy Clase 457 Ordering Dato Mutirte Columns 459 Ordering Data on the haves of an Exyrescion $59 N24 Sywerfving Custom Som Onder 460) W43 Aggregate Functions U4 Types ofSQL Functions 145 Grouping Result - GROUP BY HST Noted NS? Ms 153 4. ups ~ HAVING Clause 46) vt Group Lapressions auth GROUP BY 469) 15 Creating a Django based Basie Web Application 477-310 454 introduction 152 Whatis Web Framework? 153, How Web, Websitesand Web-applications Work? 18.4. Introducing Django 155° Installing tan 15.5.1 drstaong Dusngoin Virtual Environment 451 156 Activating Vittual Env Django Basics and Project Structure IST What are Projet and Ap in Django ? $86 1572, Understanding Django Prout Architecture 490 158. Steps toCreatea Basic Django Web Application 15.9 Creating Models, Views and Templates 1581 Creating A 159.2 Creating Templates 433 onment lls 432 1593 Creating Views 434 15.94 Creating URL. Comps 435 15.10 Writing Dictionary Data to CSV and Text Files 15.11. Practically Processing Getand Post Request ee 4a 44s AAS 4S 446 447 a7 448. 457 457 462 465 465 477 477 478 480 480 464 485 oT 492 498 490 16 Interface Python with MySQL S11 - 524 41 Introduction yt 162 Connecting to MySQL fromPython . 1621 Steps for Creating Datatune Connectivity Apptecations 512 163 Parameterised Queries 16.4. Performing InsertandUpdate Queries 17 | Society, Law and Ethics 525-580| 17.1. Introduction 172 Ethical Issues T7221 Intelintual Property Righis 526 1722 Paguram 526 PLE Digi Pnperty Rights 8 173. Open Source Philosophy and Saftware Licences TLL Termintogy 528 1732. Philmophy of Open Swurce 529 1733 Defintaons 539 I134_ Licenses and Domains of Open Source Tehnology 532 Ww 7s 6 17 178 = Ms 17.10 an W742 way Appendix AL-A.18 Privacy Online Froud Gyber Crime Computer Forensics Cyber Law and IT Act ‘Technology and Society 7.91 Eaomomic Benefit E-waste Management I2IO1 EAt¥aste Diyyns! Pravess 540 4 T2102 Refit of eWavte Recuchng 541 entity Theft Gender Issues while Teaching/Using Computers VALI Gender tssues 540 Disability sues while Teaching and Using Computers Appendix A: Utiity of Module's _name_ Appendix 8: Working with A Useful Python Library-Tkinter Appendix C: Django installation on Ubuntu Linux Abpendix D: Creating (data) Models for Djangoapps Appendix E: Insalling MySQL Python Connector Appendix F Project Creationand Distribution ee) su su 510 521 525 526 528 534 534 536 538 538 $39 540 SH 543 545 AL AQ AG AO An ll www.worldvideweb.com Python Revision Tour Tn Wis Charter 22 Introduction 18 Expressions, 12. Tokens in Python 1.9. Statement Flaw Control 1a Barebones of a Python Program 1.10 The if Condonats 24 Vanables and Assignments 111 Looping Statements: 15 Simple tnput and Output 112 Jump Statements — break and continue 16 Data Types 213, More on Loops uW Mutable and immutatte Types. INTRODUCTION You must have enjoyed learning Python in class XL. Python by Guido Vow Rossin in early 1990s, has become a vory popular Programming language among beginners as well as developers. The journey of Python that you started in clase XI will Continue in class XI as wel. In class XI, you shall learn more about Python and somesdvanced concepts, Before we start swith never topics and concepts in Python, We us revise all that you have learnt in class XL. And this chapter will be doing ju take you to the revision tour of Python that you learnt Programming language, developed he sam your previous class. ww.worldvideweb.com COMPUTER SCIENCE WITH PYTHOr _ eT 2 Powis 1.2. TOKENS IN PYTHON The smallest individual unit in a program is known as a Token or a lexical wit. The smallest indeidual unit in | program is tnown at 37 Python has following tokens : ‘nvektcet oc, hen at () Keywords (if) Identifiers (Names) _ (fii) Literals (ip) Operators (0) Punctuators = A sazple Python progran for a1,in range(1)<2 A 4 " punctuators y . ff aX2 =p . beywords teal prints Se keen enters Figure 1.1. Some tobens in a Python program. Let us revise our understanding of tokens. 3 1.2.1. Keywords Keywords are predefined words with special meaning, to the A beyiaeh ite» Wid hn language compiler or interpreter. These are reserved for special meaning reserved by special purpose and must not be used as normal identifier programming language. names. Python programming language contains the following keywords = False assert del for, in or while None break elif from is pass with True lass else. global lambda raise yield and continue except if ronlocal return as def finally impor not try 1.2.2 Identifiers (Names) Identifiers are the names given to different paris of the progearn fanetions, lists, dictionaries and so forth. The naming rules for Python identifiers can be summarized as follows : f © Variable names must only be a nom-keyword word with Po spaces in between. riables, objects, classes, © Variable names must be made up of ip of only letters, tt numbers, and underscore (_, Ce Ee ont lores n ff © Varlble names cannot begin with a number, although Matter an they can contain numbers, The following are some The following are sume invalid identifiers : valid identifiers : DATA-REC contains speaal character - (hyphen) yftte OATES 777 (other than A 7, a+z.and _ (underscore) ) F aoe aS 29cLcT ‘Starting with a digit ork FILEL3, | 4 z1ez9_WT3 1K break reserved heywor ae My.file contains special character dot (.) 1.2.3 LiteralsValues Literals are data items that have a fixed/constant value. Python allows several kinds of literals, which are being given below. (i) String Literals A string literal is « sequence of characters surrounded by quotes (single or double or triple quotes). String literals can either be single line strings or multi-line strings. © Single line strings must terminate in one line 14, the closing quotes should be on the same line as that of the opening, quotes, (See below) © Mult ine strings are strings spread across multiple lines. With single and double quotes, each line other that the concluding line has an end character as \ (backslash) but with triple quotes, no backslash is nevded at the end of intermediate lines. (sce below) : >>> Text = "Hello world? <—___ >>> Text2 © “Hello\ ss Morld* Mattie sing Single line seing Text3="**Hollos Worla!** No fuckatih nerd In strings, you can include non-geap characters through escape sequences. Escape sequences are given in following table : Escape What it does Escope | What it does __ Sequence [Non-graphic character] | __ sequence. __[Nongrophie character) \ | Backslash (\) \e Carriage Retum (CR) v Single quote () \t Horizontal Tab (TAB) uv | Double quate (") Vue Character with 16-bit hex value | xxx (Unicode only) \a ) ASCII Bell (DEL) \Urmxnx, Character with 32-bit hex value | xweeere (Unicode only) \b ASCII Backspace (BS) \v ASCII Vertical Tab (VT) Mt ASCII Formfced (FF) \o00 Character with octal value 000 \n New line character \xhh Character wwith hex value hh. ANiname} | Character named name in the Unicode database (Unicode only) COMPUTER SCIENCE ATH PYTHON — 54 (u) Numeric Literals Numeric literals are numeric values and these can be one of the following types {o) int (signed integers) often called just integers or ints, are positive or negative whole numbers with no decimal point. : The integer literals can be wrilten in : © Decimal form : an integer beginning with digits 1-9. ¢.g., 1234, 4100 etc. {© Octal form : an integer beginning with Oo (zero followed by letter 0) e., 0035, 0677 ete, Here do remember that for Octal, 6 and 9 are invalid digits. mal form : an integer beginning with Ox (zero followed by letter X) eg., 0x73, rs for hexadecimal numbers are 0-9 and © Hexadeci OxAF ete. Here remember that valid digits/ette AF. (b) Floating Point Literals. Floating point literals or real literals floats represent real numbers and are written with a decimal point dividing the integer and fractional parts are numbers having fractional parts, These can be written in fractional form eg. “130, 75, 7. ete, or in Exponent form e., 0.1765, 3.£2, GEM etc. () Complex number literals are of the form a+ bf, where a and bare floats and J (or f) represents JL, which is an imaginary number). «is the real part of the number, and b is the imaginary part. 3 (ii) Boolean Literals ‘A Boolean literal in Python is used to represent one of the two Boolean values i.c., True (Boolean, truc) or False (Boolean false), A Boolean literal can either have value as True or as False. (iv) Special Literal None Python has one special literal, which is None. The None I value. Python can also store literal collections, in the form of tuples and lists ete. | is used to indicate absence of 1.2.4 Operators Operators are tokens that trigger some computation / action when applied to variables and other objects in an expression. ‘The operators can be arithmetic operators (4, -,*, /, %, **, //), bitwise operators (&, °, |), shift operators (<<, >>), identity operators (is, is not), relational operators (>, <, >=, <=, ==, !=), logical operators (and, or), assignment operator (=), membership operators (in, not in), and arithmetic-assignment operators (J, , N=). es, 8h hee, * 1.2.5 Punctuators Purctuators are symbols that are used in programming languages to organize sentence structures, and indicate the rhythm and emphasis of expressions, statements, and program ‘structure. ‘Most common punctuators of Python programming language are : "THVOEIII@, 2.0 =

You might also like