Skip to content

Latest commit

 

History

History
248 lines (209 loc) · 6.36 KB

basic python.md

File metadata and controls

248 lines (209 loc) · 6.36 KB
# Python Basics: Your Journey Begins 🚀🐍

Welcome to the magical world of Python, where coding is a breeze and endless possibilities await you! 🪄✨

## Table of Contents
1. [Basic Python Commands](#basic-python-commands)
2. [Data Types](#data-types)
3. [Basic Operations](#basic-operations)
4. [More Basic Python Commands and Concepts](#more-basic-python-commands-and-concepts)

## 1. Basic Python Commands 🚀

### Print 🖨️
- Command: `print("Hello, Python!")`
- Explanation: The `print` function is your friendly companion for showing messages on the screen. Let's greet the world!
- Example:
  ```python
  print("Hello, Python!")

Comments 💬

  • Command: # This is a comment
  • Explanation: Comments are your secret notes that only you can read. Use them to explain your code.
  • Example:
    # This is a comment

Variables 📦

  • Command: variable_name = value
  • Explanation: Think of variables as containers where you can store anything you like. Give them a name, and they'll remember it for you!
  • Example:
    age = 20
    name = "Alice"

User Input 🤖

  • Command: input("Enter your name: ")
  • Explanation: The input function is like having a conversation with your code. It asks for your input, and you respond!
  • Example:
    name = input("Enter your name: ")

2. Data Types 🧰

Integer (int) 🔢

  • Explanation: Integers are whole numbers without decimal points. Perfect for counting your blessings!
  • Example:
    age = 25

Floating-Point (float) 🌊

  • Explanation: Floating-point numbers have decimal points and are your go-to choice for anything that's not whole.
  • Example:
    price = 19.99

String (str) 📜

  • Explanation: Strings are like a string of pearls, holding characters together. Use quotes to define them.
  • Example:
    name = "Bob"

Boolean (bool) 🧐

  • Explanation: Booleans have only two answers - "Yes" (True) and "No" (False). They're your code's way of making decisions.
  • Example:
    is_python_fun = True

List 📋

  • Explanation: Lists are like your shopping list; they can contain many items. They're your flexible friends!
  • Example:
    fruits = ["apple", "banana", "cherry"]

Tuple 🧷

  • Explanation: Tuples are like lists, but once you make them, they're set in stone! They're perfect for things that shouldn't change.
  • Example:
    coordinates = (3, 5)

Dictionary 📚

  • Explanation: Dictionaries are like word dictionaries - they store words (keys) and their meanings (values).
  • Example:
    person = {"name": "Alice", "age": 30}

Set 🎈

  • Explanation: Sets are like a bag of unique surprises; they only contain unique elements!
  • Example:
    unique_numbers = {1, 2, 3, 4, 5}

NoneType (None) 🤷

  • Explanation: None is like a blank slate. It means "I don't know" or "There's nothing here."
  • Example:
    no_value = None

3. Basic Operations 🎯

Arithmetic Operators 🧮

  • Explanation: These operators perform math operations like adding, subtracting, multiplying, and more.
  • Example:
    result = 10 + 5

Comparison Operators 🧐

  • Explanation: Use these to compare values and decide if something is true or false.
  • Example:
    is_equal = 5 == 3

Logical Operators 🧠

  • Explanation: Logical operators help your code make smart decisions by combining and negating values.
  • Example:
    is_true = True and False

String Concatenation 🍔

  • Explanation: String concatenation is like making a sandwich with words. Combine strings with a + to make a new one.
  • Example:
    first_name = "John"
    last_name = "Doe"
    full_name = first_name + " " + last_name

Type Conversion 🔄

  • Explanation: Sometimes, you need to change the way data looks or behaves. Use type conversion functions.
  • Example:
    age_str = "30"
    age_int = int(age_str)

4. More Basic Python Commands and Concepts 📝

Math Functions ➕

  • Explanation: Python has built-in math functions for all your number-crunching needs.
  • Example:
    absolute_value = abs(-5)

String Length 📏

  • Explanation: Find out how long a string is using the len function.
  • Example:
    sentence = "Python is amazing!"
    length = len(sentence)

String Slicing 🍰

  • Explanation: Slice a piece of a string to enjoy just the part you like.
  • Example:
    text = "Hello, World!"
    sliced_text = text[0:5]  # Extracts "Hello"

String Methods 🧰

  • Explanation: Strings come with a toolkit of methods. Use them to manipulate and transform your text.
  • Example:
    text = "python is great"
    uppercase_text = text.upper()

If-Else Statements 🚦

  • Explanation: Use if, elif, and else to make decisions in your code.
  • Example:
    age = 18
    if age >= 18:
        print("You are an adult")
    else:
        print("You are not an adult")

While Loops 🔄

  • Explanation: Create loops that keep going as long as a condition is true.
  • Example:
    count = 1
    while count <= 5:
        print("Count: ", count)
        count += 1

For Loops 🚗

  • Explanation: Loop over a sequence like a list or string and do something with each item.
  • Example:
    fruits = ["apple", "banana", "cherry"]
    for fruit in fruits:
        print("I like", fruit)

Function Definitions 🎁

  • Explanation: Define your own functions to package up code and use it whenever you want.
  • Example:
    def greet(name):
        print("Hello, " + name + "!")
    greet("Alice")

Built-in Functions 🧡

  • Explanation: Python has a treasure chest of built-in functions to save you time and effort.
  • Example:
    numbers = [3, 7, 1, 9, 4]
    max_value = max(numbers)

Logical Expressions 🧩

  • Explanation: Combine and compare values with logical expressions to make your code smarter.
  • Example:
    is_sunny = True
    is_warm = True
    if is_sunny and is_warm:
        print("It's a great day!")

These concepts and examples are your stepping stones to a world of Python possibilities. Dive in, explore, and have fun coding! 🚀🐍✨

Feel free to use this friendly and easy-to-understand.Happy coding! 🌟👩‍💻👨‍💻🚀