Main menu

Pages

Learn Python #1 print / strings

  Learn Python #1
print / strings




Why Learn Python?



Python is a multi-purpose, versatile, and popular programming language which was created by Guido van Rossum, and released in 1991. With Python you can build almost anything like mobile apps, web apps, tools, data analytics, machine learning etc. It's great as a first language because it's concise and easy to learn comparing with other languages like c++, Java, C#.


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.


Good Job... you wrote your first program in Python.

Our next step is to learn how to deal with strings:

Strings in Python:


Strings are a sequence of characters, characters are symbols (letters, numbers, !, @, #, ... etc).

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?



Notes: - the line after the # considered as a comment.

           - 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.

author-img
Yet another human being that's passionate about Data Science, AI, programming & Math.

Comments

1 comment
Post a Comment

Post a Comment