Thursday, 8 May 2025

Python Intro + Install, Hello World + Comments, Variables & Data Types

🐍 Python Tutorial for Absolute Beginners


📘 Topic: Python Intro + Install, Hello World + Comments, Variables & Data Types



🔹 1. Introduction to Python

What is Python?

Python is a high-level, interpreted, general-purpose programming language that is known for its simplicity and readability. It is widely used in web development, data science, artificial intelligence, machine learning, automation, and more.

Key Features of Python:

  • Easy-to-read syntax

  • Large standard library

  • Dynamically typed

  • Open-source and community-driven

  • Cross-platform

  • Extensive third-party modules (e.g., NumPy, pandas, Django)

Why Learn Python?

  • Beginner-friendly

  • Versatile and powerful

  • In-demand skill for jobs in tech, data, and science

  • Great community and resources


🔹 2. Installing Python

Step-by-Step Installation Guide:

For Windows:

  1. Visit: https://www.python.org/downloads/

  2. Download the latest version (e.g., Python 3.12.x).

  3. Run the installer.

  4. Important: Check the box “Add Python to PATH” before clicking "Install Now".

  5. After installation, open Command Prompt and type:

    python --version

    You should see the installed Python version (e.g., Python 3.12.0).

For macOS:

  1. Use Homebrew (recommended):

    brew install python
  2. Or download from python.org.

For Linux:

Install via terminal:

sudo apt update sudo apt install python3

Check version:

python3 --version

🔹 3. Writing Your First Python Program (Hello World)

Using the Command Line

  1. Open your terminal or command prompt.

  2. Type:

    python
  3. Enter:

    print("Hello, World!")

You should see:

Hello, World!

Using a Script File

  1. Open a code editor like VS Code, Sublime Text, or Thonny.

  2. Create a new file and name it hello.py.

  3. Write the following code:

    print("Hello, World!")
  4. Save the file.

  5. Run the script from terminal:

    python hello.py
    


🔹 4. Comments in Python

Comments help you explain what your code does. Python supports:

🔸 Single-Line Comments

Use # before the comment:

# This is a single-line comment print("Python is fun!") # This is an inline comment

🔸 Multi-Line Comments

Use triple quotes (''' or """):

""" This is a multi-line comment. It can span multiple lines. """ print("Multiline comment above")

Note: Triple quotes are also used for documentation (docstrings).


🔹 5. Variables in Python

What is a Variable?

A variable is a name that refers to a value stored in memory.

name = "Alice" age = 25 is_student = True

Rules for Naming Variables:

  • Must start with a letter or underscore _

  • Cannot start with a number

  • Can include letters, numbers, and underscores

  • Are case-sensitive (name and Name are different)

Example:

city = "New York" temperature = 21.5 is_raining = False print(city) print(temperature) print(is_raining)







🔹 6. Python Data Types

Python is dynamically typed, meaning you don’t need to declare a type—it figures it out.

Here are the most commonly used data types:


6.1 🔢 Numbers

Integer (int):

x = 10 print(type(x)) # <class 'int'>


Float (float):

pi = 3.1415 print(type(pi)) # <class 'float'>


Complex (complex):

z = 2 + 3j print(type(z)) # <class 'complex'>



6.2 🔤 Strings

Strings are sequences of characters.

message = "Hello, Python!" print(message) print(len(message)) # Length of string print(message.upper()) # HELLO, PYTHON!

You can use single ' or double " quotes:

s1 = 'Python' s2 = "Rocks"

6.3Booleans

Only two boolean values: True and False

is_sunny = True is_night = False print(type(is_sunny)) # <class 'bool'>


6.4 📦 Lists

Lists are ordered, mutable, and can hold mixed types.

fruits = ["apple", "banana", "cherry"] print(fruits[0]) # apple fruits.append("orange") print(fruits)


6.5 📦 Tuples

Tuples are like lists but immutable.

coordinates = (10, 20) print(coordinates)


6.6 🧾 Dictionaries

Dictionaries store key-value pairs

person = { "name": "Alice", "age": 30, "city": "London" } print(person["name"]) # Alice


6.7 🔢 Sets

Sets are unordered, and no duplicate values.

nums = {1, 2, 3, 2, 1} print(nums) # Output: {1, 2, 3}


🔹 7. Type Casting

Convert between data types using casting functions.

x = 5 y = float(x) z = str(x) print(y) # 5.0 print(z) # "5"

Casting functions:

  • int()

  • float()

  • str()

  • bool()


🔹 8. The type() and id() Functions

  • type(variable) → returns the type of the value.

  • id(variable) → returns the unique memory location.

a = 10 print(type(a)) # <class 'int'> print(id(a)) # e.g., 140739212139920


🔹 9. Best Practices for Beginners

  • Use clear, meaningful variable names.

  • Add comments where needed.

  • Keep your code clean and consistent.

  • Use an IDE or code editor with syntax highlighting.

  • Practice often!


🔹 10. What’s Next?

Now that you understand the basics:

  • Install Python

  • Run your first program

  • Use comments

  • Declare variables

  • Work with data types

Next topics to learn:

  • Control Flow (if, else, elif)

  • Loops (for, while)

  • Functions

  • Error handling

  • Object-Oriented Programming


🎯 Conclusion

Python is an excellent first language, and now you’ve taken your first big step. Practice writing small scripts, experiment with variables and data types, and build your confidence!

Share:

Saturday, 3 June 2023

Friday, 2 June 2023

Wednesday, 16 November 2022

Kwiqshop App Website

 


Kwiqshop App Website describes in detail, the kwiqshop  

e-commerce App.

Share:

Friday, 4 November 2022

The Advantages of Ecommerce for a Business Con't:

 


Low costs:

The fact that creating a website is always less expensive than opening a physical store is one of the major advantages of e-commerce. You are not required to supply your business, pay rent, or engage numerous staff members to operate there. Additionally, marketing and promotion tactics are inexpensive.

The lack of a middleman lowers the cost price to a greater extent, which is one of the key benefits of e-commerce. The portal can generate an efficient supply chain because a direct connection between buyer and seller is established.

Additionally, the internet portal is automated and mechanized, which helps save a significant sum of money. Yes, if you want a customized website, you will have to make a minor sacrifice, but you already have a consumer base of compulsive online shoppers.

Share:

Saturday, 29 October 2022

The Advantages of Ecommerce for a Business:



Introduction:

E-commerce is one of the world's fastest growing retail industries. The advancement of science and technology, as well as the widespread availability of internet access, has had a direct impact on consumer attitudes.

The majority of them are simply not interested in spending hours in shopping malls exploring a variety of goods. The younger generation today prefers to shop at their convenience rather than following the guidelines of stores that have set hours of operation. E-commerce is seen as a potent tool that has aided in the growth of internet commerce. Daily transactions on various e-commerce portals total close to 1.2 million.

Without the help of the middleman, it has been successful in connecting the customer and seller to a single platform. Because the internet market is open around-the-clock, convenience is one of the key factors contributing to its appeal. As a result of the companies' ability to make cost savings, it is also quicker and less expensive.

Kwiqshop App is an Android App which enables Users to create accounts. These network of Users, can post items on their page and sell. At the same time, they can also buy products posted by others. For more information on the app please visit Kwiqshop App Website.



 

Share:

Wednesday, 2 February 2022

Android AlertDialog Example using kotlin Programming language.

 This example shows how to use Android Studio and Kotlin to develop an AlertDialog in Android.



Step 1 − Create a new project in Android Studio by going to File New Project and filling in all of the necessary details.

Step 2 − In res/layout/activity main.xml, add the following code.

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="98dp"
        android:textAlignment="center"
        android:textColor="#EA0B0B"
        android:textSize="50sp"
        android:text="@string/alertdialog_example_using_kotlin"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

Step 3 − Add the following code to src/MainActivity.kt

package com.alfrosoft.alertdialogexample

import android.content.DialogInterface
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.appcompat.app.AlertDialog

class MainActivity : AppCompatActivity() {

    var alertDialog: AlertDialog? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        createDialog()
    }

    private fun createDialog() {
        val alertDialogBuilder = AlertDialog.Builder(this)
        alertDialogBuilder.setTitle("Exit App")
        alertDialogBuilder.setMessage("Are you sure you want to exit?")
        alertDialogBuilder.setPositiveButton("Yes") { _: DialogInterface, _: Int ->
            finish()
        }
        alertDialogBuilder.setNegativeButton("Cancel") { _: DialogInterface, _: Int -> }

        alertDialog = alertDialogBuilder.create()
    }

    override fun onBackPressed() {
        alertDialog?.show()
    }
}

Step 4 − Add the following code to androidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.alfrosoft.alertdialogexample">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.AlertDialogExample">
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Step 5 - Let's run the application. I'm assuming you've already connected your actual Android Mobile device to your computer or configured your emulator.




Share:

BTemplates.com

Powered by Blogger.

Contact form

Name

Email *

Message *

Search This Blog

POPULAR-desc:Trending now:

Translate

SEARCH

Popular

Blog Archive