Docsity

Learn Python programming Language., Summaries of Computer science

Partial preview of the text

Download Learn Python programming Language. and more Summaries Computer science in PDF only on Docsity!

Table Of Content

  • Variables And Arithmetic

Operations in python.

  • Input and Output in Python.
  • Data Types in Python.
  • Statements in Python.
  • While Loop in Python.

Arithmetic operators are used to performing

mathematical operations like addition, subtraction, multiplication, and division. There are 7 arithmetic operators in Python :

  • Addition Operator : In Python, + is the addition operator. It is used to add 2 values.
  • Subtraction Operator: In Python, – is the subtraction operator. It is used to subtract the second value from the first value.
  • Multiplication Operator: In Python, __* is the multiplication operator. It is used to find the product of 2 values.
  • Division Operator: In Python, / is the division operator. It is used to find the quotient when the first operand is divided by the second.
  • Modulus Operator: In Python, % is the modulus operator. It is used to find the remainder when the first operand is divided by the second.
  • Exponentiation Operator: In Python, __** is the exponentiation operator. It is used to raise the first operand to the power of the second.
  • Floor division: In Python, // is used to conduct the floor division. It is used to find the floor of the quotient when the first operand is divided by the second.

Input and Output in

python

1) input () function In Python, sometimes we might want to take input from the user. We can do so by using the input() function. Python takes all the input as a string input by default. This function first takes the input from the user and converts it into a string. The type of the returned object always will be <type ā€˜str’>. It does not evaluate the expression it just returns the complete statement as String. 2) print() function we use the print () function to output data to the screen. The Python print() function takes in any number of parameters, and prints them out on one line of text print () just prints the statement and nothing else.

Examples of Data Types in Python Python is a dynamically typed language, meaning that the data type of a variable is inferred at runtime based on the value it is assigned. Here are some examples of data types in Python:

  • Integer: (css) a = 10 b = - 5
  • Float: Makefile c = 3. d = - 2. Python also has other data types, such as lists, tuples, and dictionaries, which are used to store collections of values. Understanding the different data types and how to use them is essential for writing effective Python programs.
    • String: Makefile e = "Hello, world!ā€œ f = 'Python is fun!’
    • Boolean: g = True h = False

Statements

in Python

Decision-making is the most important aspect of almost all programming languages. As the name implies, decision-making allows us to run a particular block of code for a particular decision. Here, the decisions are made on the validity of the particular conditions. Condition checking is the backbone of decision-making. In python, decision decision-making is performed by

the following statements.

  • The if statement is used to test a particular condition and if the condition is true, it executes a block of code known as an if-block. The condition of an if statement can be any valid logical expression that can be either evaluated as true or false.
  • The if-else statement provides an else block combined with the if statement which is executed in the false case of the condition. If the condition is true, then the if-block is executed. Otherwise, the else block is executed.
  • The elif statement enables us to check multiple conditions and execute the specific block of statements depending upon the true condition among them. We can have any number of elif statements in our program depending upon our need. However, using Elif is optional.