Skip to content

python basics

  1. Print Statements:Printing text to the console is often the first thing you learn in any programming language. In Python, you can use the print() function:pythonCopy codeprint("Hello, World!")
  2. Variables:Variables are used to store data. Python is dynamically typed, so you don’t need to declare the data type explicitly.pythonCopy codename = "John" age = 30
  3. Data Types:Python supports various data types, including integers, floats, strings, booleans, and more.pythonCopy codenum = 42 pi = 3.14 text = "Python" is_student = True
  4. Lists:Lists are used to store a collection of items.pythonCopy codefruits = ["apple", "banana", "cherry"]
  5. Loops:You can use loops to perform repetitive tasks.pythonCopy codefor fruit in fruits: print(fruit)
  6. Conditional Statements:Conditional statements like if, elif, and else allow you to make decisions in your code.pythonCopy codeage = 18 if age < 18: print("You are a minor.") elif age == 18: print("You are just 18!") else: print("You are an adult.")
  7. Functions:Functions allow you to encapsulate code into reusable blocks.pythonCopy codedef greet(name): print("Hello, " + name + "!") greet("Alice")
  8. Comments:Comments are used to add explanations to your code.pythonCopy code# This is a comment
  9. User Input:You can get input from the user using the input() function.pythonCopy codename = input("What's your name? ")
  10. Indentation:Python uses indentation (whitespace) to define code blocks, unlike languages that use braces or keywords.
pythonCopy codeif condition:
    # This is inside the if block
    print("It's true!")
# This is outside the if block

These are some of the very basics of Python. As you continue learning, you’ll explore more advanced topics like classes, modules, file I/O, and libraries for specific tasks. Python has a rich ecosystem and is a great language for beginners and experienced programmers alike.

Leave a Reply

Your email address will not be published. Required fields are marked *


Enjoy this blog? Please spread the word :)