mirror of
https://github.com/michivonah/python.git
synced 2025-12-22 20:46:29 +01:00
create example for basics
This commit is contained in:
parent
9f569cac7b
commit
3798905807
2 changed files with 56 additions and 0 deletions
9
basics/basics.md
Normal file
9
basics/basics.md
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
# Basics in Python
|
||||||
|
|
||||||
|
## String functions
|
||||||
|
|
||||||
|
## Core concepts
|
||||||
|
Check if execution is in main program
|
||||||
|
````python
|
||||||
|
if __name__ == '__main__':
|
||||||
|
````
|
||||||
47
basics/main.py
Normal file
47
basics/main.py
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
# Basics in Python
|
||||||
|
# Michi von Ah - October 2023
|
||||||
|
|
||||||
|
# Data structures
|
||||||
|
# Array
|
||||||
|
brands = ["Apple", "Samsung", "Google", "OnePlus"]
|
||||||
|
|
||||||
|
# Dictionary
|
||||||
|
phone = {
|
||||||
|
"brand": "Apple",
|
||||||
|
"model": "iPhone 14 Pro",
|
||||||
|
"cameras": 3
|
||||||
|
}
|
||||||
|
|
||||||
|
# Dictionaries in Array
|
||||||
|
phones = [
|
||||||
|
{
|
||||||
|
"brand":"Apple",
|
||||||
|
"model":"iPhone 14 Pro",
|
||||||
|
"cameras":3,
|
||||||
|
"memory":"6GB"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"brand":"Samsung",
|
||||||
|
"model":"Galaxy S23",
|
||||||
|
"cameras":3,
|
||||||
|
"memory":"8GB"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
# Split strings into Array
|
||||||
|
fruits = "Apple,Banana,Pear,Cherry"
|
||||||
|
split = fruits.split(",") # Output: ['Apple', 'Banana', 'Pear', 'Cherry']
|
||||||
|
|
||||||
|
# Transform text
|
||||||
|
text = "I love Python!"
|
||||||
|
|
||||||
|
upper = text.upper() # Output: I LOVE PYTHON!
|
||||||
|
lower = text.lower() # Output: i love python!
|
||||||
|
|
||||||
|
# Convert String-To-Int and Int-To-String
|
||||||
|
number = 12
|
||||||
|
numberConverted = int("12")
|
||||||
|
|
||||||
|
string = "Hello World"
|
||||||
|
|
||||||
|
combined = string + str(numberConverted) # Output: Hello World12
|
||||||
Loading…
Add table
Add a link
Reference in a new issue