INF1511-Python SUMMARY.
Phyton Powerful high-level, dynamic object-oriented programming INTRODUCTION Features of Python Python is easy to learn. It has easier to read syntax. It uses white space to indent lines for defining blocks instead of using brackets. Python is free. It comes with a large number of libraries included, and there are many more that you can download and install. Python can be integrated with other languages, like C, C++, and Java. Python is an interpreted language, therefore it supports a complete debugging and diagnostic environment making the job of fixing mistakes much faster. Python is a good choice for web development, networking, games, data processing, and business applications. For efficient memory management, Python uses garbage collection, so you don’t have to worry about memory leaks. Python supports exception handling. Interacting with Python Using Command Line Mode Using IDLE IDE Command Line Mode Since whatever you type in command line mode is not saved, it is better to save code in a file and then execute it. You can run Python programs from the command prompt. Open the command prompt and type python followed by the Enter key to open Python and tell it to run the script file, . IDLE (Integrated DeveLopment Environment) The program will be saved with extension .py. To execute the program, select Run Run Module or press the F5 key. Remember to add the .py extension when saving the file. Indentation Python uses indentation to express the block structure of a program. Unlike other languages, Python does not use braces or begin/end delimiters to denote blocks. Instead it uses indentation to represent blocks of statements. A block is a contiguous sequence of logical lines, all indented by the same amount, and a logical line with less indentation ends the block. The first statement in a block must have no indentation—it must not begin with any white space. You can use tabs or spaces to indent statements. Python replaces each tab with up to eight spaces. Don’t mix spaces and tabs for indentation, as tabs may be treated differently by different editors. Data Types in Python Integers: Integers are 32 bits long, and their range is from –232 to 232 – 1 (i.e., from –2,147,483,648 to 2,147,483,647). INF1511-Python SUMMARY. Long Integers: It has unlimited precision, subject to the memory limitations of the computer. Floating Point Numbers: Floating-point numbers are also known as double-precision numbers and use 64 bits. Boolean: It can hold only one of two possible values: True or False. Complex Number: A complex number has a real and an imaginary component, both represented by float types in Python. An imaginary number is a multiple of the square root of minus one, and is denoted by j. For instance, 2+3j is a complex number, where 3 is the imaginary component and is equal to 3 × √−1. Strings: Sequences of Unicode characters. Lists: Ordered sequences of values. Tuples: Ordered, immutable sequences of values. Sets: Unordered collections of values. Dictionaries: Unordered collections of key-value pairs. UNICODE Unicode uses 16 bits & represents characters by integer value denoted in base 16. ASCII (American Standard Code for Information Interchange) - 8 bits Mutable & immutable An object that can be altered is known as a mutable object, One that cannot be altered is an immutable object. BASIC ELEMENTS IN A PROGRAM Literals A number or string that appears directly in a program You can use both single and double quotes to represent strings. The strings that run over multiple lines are represented by triple quotes. 10 # Integer literal 10.50 # Floating-point literal 10.50j # Imaginary literal 'Hello' # String literal "World!" # String literal '''Hello World! It might rain today # Triple-quoted string literal Tomorrow is Sunday''' Variables Variables are used for storing data in a program. Keywords Python has 30 keywords, which are identifiers that Python reserves for special use. Keywords contain lowercase letters only. You cannot use keywords as regular identifiers. and assert break class continue def del elif else except exec finally for from global if import in is lambda not Comments Comments are the lines that are for documentation purposes and are ignored by the interpreter. Use a (#). Continuation Lines A physical line is a line that you see in a program. A logical line is a single statement in Python terms. In Python, the end of a physical line marks the end of most statements If statement is too long to fit in single line: ensuring that the first physical line has no comment and ends with a backslash (). Python also joins adjacent lines into one logical line if an open parenthesis ( ( ), bracket ( [ ), or brace ( { ) is not closed. The lines after the first one in a logical line are known as continuation lines. The indentation is not applied to continuation lines but only to the first physical line of each logical line
Written for
- Institution
- University of South Africa
- Course
- INF1511 - Visual Programming I
Document information
- Uploaded on
- November 25, 2021
- Number of pages
- 89
- Written in
- 2021/2022
- Type
- SUMMARY
Subjects
-
inf1511
-
inf1511 python summary