Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
7 views

Basic Terms For Python3

Uploaded by

ashfaqahad08
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Basic Terms For Python3

Uploaded by

ashfaqahad08
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Basic Terms For Python :

 Strings: Computer programmers refer to blocks of text as strings. In our


last exercise, we created the string “Hello world!”. In Python a string is either
surrounded by double quotes ("Hello world") or single quotes ('Hello
world'). It doesn’t matter which kind you use, just be consistent.

 Variables: Programming languages offer a method of storing data for


reuse. If there is a greeting we want to present, a date we need to reuse, or a
user ID we need to remember we can create a variable which can store a value.
In Python, we assign variables by using the equals sign (=).

1. Cant have symbols or spaces in the middle except and underscore(_).

Errors: Humans are prone to making mistakes. Humans are also typically in
charge of creating computer programs. To compensate, programming languages
attempt to understand and explain mistakes made in their programs.

Python refers to these mistakes as errors and will point to the location where an
error occurred with a ^ character. When programs throw errors that we didn’t expect
to encounter we call those errors bugs. Programmers call the process of updating
the program so that it no longer produces unexpected errors debugging.

1.Two common errors that we encounter while writing Python


are SyntaxError and NameError.

 SyntaxError means there is something wrong with the way your program is
written — punctuation that does not belong, a command where it is not
expected, or a missing parenthesis can all trigger a SyntaxError.
 A NameError occurs when the Python interpreter sees a word it does not
recognize. Code that contains something that looks like a variable but was
never defined will throw a NameError.
Numbers: Computers can understand much more than just strings of text.
Python has a few numeric data types. It has multiple ways of storing numbers. Which
one you use depends on your intended purpose for the number you are saving.

An integer, or int, is a whole number. It has no decimal point and contains all
counting numbers (1, 2, 3, …) as well as their negative counterparts and the number
0. If you were counting the number of people in a room, the number of jellybeans in
a jar, or the number of keys on a keyboard you would likely use an integer.

A floating-point number, or a float, is a decimal number. It can be used to


represent fractional quantities as well as precise measurements. If you were
measuring the length of your bedroom wall, calculating the average test score of a
seventh-grade class, or storing a baseball player’s batting average for the 1998
season you would likely use a float.

 Calculations: Computers absolutely excel at performing calculations. The


“compute” in their name comes from their historical association with
providing answers to mathematical questions. Python performs the arithmetic
operations of addition, subtraction, multiplication, and division with +, -, *,
and /.

Notice that when we perform division, the result has a decimal place. This is
because Python converts all ints to floats before performing division. In older
versions of Python (2.7 and earlier) this conversion did not happen, and integer
division would always round down to the nearest integer.

Division can throw its own special error: ZeroDivisionError. Python will raise this
error when attempting to divide by 0.

Mathematical operations in Python follow the standard mathematical

 Exponents: Python can also perform exponentiation. In written math, you


might see an exponent as a superscript number, but typing superscript
numbers isn’t always easy on modern keyboards. Since this operation is so
related to multiplication, we use the notation **.
Concatenation: The + operator doesn’t just add two numbers, it can also
“add” two strings! The process of combining two strings is called string
concatenation. Performing string concatenation creates a brand new string
comprised of the first string’s contents followed by the second string’s contents
(without any added space in-between).

 Bugs: When programs throw errors that we didn’t expect to encounter, we


call those errors bugs. Programmers call the process of updating the program
so that it no longer produces bugs debugging.

You might also like