Python Coding Language. Python is A Powerful and Versatile Programming Language Part 2
Python coding language Part 2.
Software requirement for Python programming language:
-
Python Language 3.11 or 3. xxx
- Here is the official website link of Python OOP Language :
-
Pycharm 2022 Editor (IDE) for Python coding environment :
- Here is the official website link of Python Editor (PyCharm)
Language Topics:
- Introduction of Language
- Output functions
- Input function
- Operators
- Escape sequences
- Data types
- Conditional statements
- Loops
- Arrays (collection of data)
- Functions
- Classes
- Object
- Variable
- constant
Language Introduction:
- Communication way is called language:
- Language must be the same on both sides
- If not what is the solution?
- Solution is translator
Translator:
Convert from one language to another.
Translator types:
- Line by line (Interpreter)
- Read the whole program and then give the result. (compiler)
Language types:
- Low-level languages
- Special purpose languages
- For example:
- Machine Language
- Assembly language
- Low-level programming apps
- Operating system
- Windows
- Linux
- Mac
- DOS
- Unix
- Android
- Window
- iOS
- Virus
- Anti-virus
- Driver
- etc. etc.
- Operating system
- For example:
- Special purpose languages
- Haigh-level languages
- Common purpose languages:
- c/c++
- java
- javascript
- Python
- Php
- Html
- GW Basic
- etc. etc.
- Common purpose languages:
Language has:
- Alphabets: a single alphabet letter è char à
- Word: a set of chars is called a word è key word à word or short word
- Statement: a set of words is called statementsè conditions & loops
- Paragraph: a set of statements is called paragraphèfunction à()
Start Coding:
run PyCharm, create a new Python file and then start programming
First of all, we discuss about output function print():
print() output function:
Python provides many ways to output data, but the most common way is to use the print() function. The print() function takes any number of arguments and prints them to the standard output device, which is usually the console.
Syntax:
print(‘any text’ OR print(“Any text”)
Note: We can use single or double quotation for string (text) data.
More detail of Syntax:
Syntax:
- print(“Any text”) or print(‘any text’)
- print(‘any text’, attrib=’value’ …) è end= attribute
- print(numeric value)
- print(variable)
- print(‘ant text’, variable)
Example:
print('This is my 1st program of Python')
This will print the string to the console. (you can look console panel is following)
output:
Example-2:
Example: text passing through variable (tx1 is a variable)
tx1='This is my 1st program of Python'
print(tx1)
Output
Example: (with, separator)
the following code will print the strings "Nadir" and "Nadeem" to the console on the same line:
print('Nadir', 'Nadeem')
Output
Different methods of printing text and values by using the print() function in Python Codding Language
# Print a simple string.
print(My first program!")
# Print the value of a variable.
name = "Ali"
print(name)
# Print multiple values on the same line.
print("Hi", name, "!")
# Print formatted output.
print("My name is {} and I am {} years old.".format(name, 25))
# Print output without a newline character at the end.
print("Hi", "Jani!", end="")
More about the print() output function
In addition to the print() function, Python also provides several other functions for outputting data, such as the write() function and the sys. stdout.write() function. However, the print() function is the most commonly used function for outputting data in Python.
Here are some tips to use the print() function effectively:
- Use the print() function to print debug messages to the console. This can help you identify and fix problems in your code.
- Use the print() function to print the results of your calculations to the console. This can help you verify that your code is working correctly.
- Use the print() function to format your output in a way that is easy to read and understand. For example, you can use the sep keyword argument to specify a separator between printed values.
The print() function in Python has the following properties (Attributes) :
The following table lists the attributes of the print()
function:
Attributes (Properties) |
Description |
|
The separator to use between the positional arguments. |
|
The string to print at the end of the output. |
|
The file object to print to. |
|
A Boolean value indicates whether to flush the output buffer after printing. |
The print()
function in Python has the following attributes:
- Positional arguments: The
print()
function can take any number of positional arguments. These arguments will be printed to the console, separated by spaces. - Keyword arguments: The
print()
function also accepts a number of keyword arguments. These arguments can be used to control the output of theprint()
function.
Here is an example of how to use the positional and keyword arguments of the print()
function:
Examples with attributes
1:- sep="" attribute
# Print the strings "Hi" and "Farry!" to the console on the same line, separated by a hyphen.
print(
"Hi",
"Farry!", sep=
"-")
Output:
Hi-Farry!
2:- end="" attribute
# Print the strings "Hi" and "Farry!" to the console on the same line, without a newline character at the end.
print(
"Hi",
"Farry!", end=
" ")
Hi Farry!
2.1:- end="" with escape sequence like \n , \t, \b etc
# we can also use esqape sequances in end='\n' attributr
print('Hi Farry', end='\n')
print (' how are you ' )
output:
Hi Farry
how are you
2.2:- end=" with text "
print("Hi", end=' Studytoday ')
print("you are awesome")
output
Hi Studytoday you are awesome
2.3:- end=" " and use a semicolon (;) if you want to write more than one statement in a single line
n='Farray'
a=23
print(n,end=' '); print(a)
output
Farray 23