What is... Python ? Easy to learn !
When you make conversation, you use a language like English. In the computer, you can talk to your computer in programming language to make them work !
Python is the one of the languages where you can talk to the computer. We're going to learn how to use python ๐
First, just download python. Search on google "Python"
Second, you can set up "Visual studio code" or "Pycharm" to run the Python easily
1. Print
if you just type words like "hello", computer receive the word but not showing on the screen.
To make them show on the screen , we say, print("hello")
print("hello")
2. Variables and Data Types
In Python, you can designate valuables like "character's name or age"
let's say you want to make 100 sentences and they're all have same variable. you may not want to put the variable at every single sentences. In Python, It makes things easier.
--------------------
Let's say,, character's name is so long ? let's make this
character_name = "Jayeeeeeeeeeeeeeeeeeeeeeeeeee"
chracter_age = "30"
print(character_name + " goes to school everyday" + " he is " + chracter_age + "." + character_name + " also likes pasta and pizza.")
and "run"
Jayeeeeeeeeeeeeeeeeeeeeeeeeee goes to school everyday he is 30.Jayeeeeeeeeeeeeeeeeeeeeeeeeee also likes pasta and pizza.
Remember you need "" or '' to print string :)
3. len
len function tells you how many words in there
phrase = "Jay world"
print(len(phrase))
9
4. [ ]
you can specify the index inside the square brackets
phrase = "Jay world"
print(phrase[0])
J
In Python , string gets index starting with 0
Jay world
012 3 45678
following this function
phrase = "Jay world3"
print(phrase[4])
you'll get "w"
Backwards:
it starts with -1
phrase = "Jay world"
print(phrase[-3])
In here, you'll get "r"
phrase = "Jay world"
print(phrase[-6])
What are you going to get ?
-------------------------------------- " " (space)
5. Index
index function tells you where a specific character or string is located !
phrase = "Jay world"
print(phrase.index("r"))
you'll get "6"
if you type like this
phrase = "Jay world"
print(phrase.index("wor"))
you'll get "4" because 'w' is the start index in the phrase.
6. Replace
If you want to replace some string or character, you can use "replace" function.
replace("A", "B") : A is the one that you want to change, B is the one to replace with
phrase = "Jay world"
print(phrase.replace("Jay", "Fun"))
Now you're going to get "Fun world" instead of Jay world.