Learn Python #1
print / strings
Why Learn Python?
The Skills:
This series of lessons is a great introduction to both basic programming concepts and the Python programming language. Eventually, you will feel comfortable programming in Python and get your skills out of your computer.
What will we learn in this lesson:
- Using print statement.
- Dealing with strings in Python.
Keywords: Python, programing, print, strings.
Let's go:
To start coding in python first you have to open Python IDE to write code (no need to install python like online-python.com).
print in Python:
Our first statement is print. the print statement must be written in small caps then leave a space then write (" "), inside the double quotes you can write whatever you want and then click run as following:
The result of running the statement will appear in the lower part of the IDE window. If there is any error, an error message will appear in the result part with the place of error.
Strings in Python:
Strings can be created by enclosing characters inside a single quote or double-quotes. Even triple quotes can be used in Python but generally used to represent multiline strings and docstrings.
How to access characters in Python?
- the position of the first character is 0.
- the position of the last character is -1.
- to get a part of a string we use the range [pos1,pos2]
where the pos1, pos2 are the first and last position of the part in that string.
Python String Operations
we used the "+" sign to add strings and "-" sign to repeat the string.
Here, we used the methods:
- join to join strings into one string.
- find to find the first appearance of a substring in a string.
- replace to replace substring with other in the original string.
Finally, I hope that I have succeeded in showing a simplified explanation of the first steps of getting started in Python, and those who are interested only have to try these instructions. so, that we can move on to the next tasks successfully.
Well done
ReplyDelete