Hi All,
This is my very first blog. I'm a Biomath student who has zero knowledge about computer related stuffs.
Later, I was convinced to study a programming language yet confused with how,where and what to start...?
And finally decided to learn python, as people around me implied that it's easy to start with... So, now I'm learning python from an online platform., which teaches me so fine...
I thought of blogging it all, cause people like me will get to know that python isn't overly challenging rather as simple as English grammar.
So, join with me...
Let's start to learn PYTHON
PYTHON BASICS
1. Printing a String :
To print a text, we use print function - print()
Let's begin with "Hello World".
By writing certain text within the print function inside double or single quotes, we get :
print("Hello World") HelloWorld
2. Similarly, we can Print Variables :
- Variables are used to store data.
name = "Abys" print(name) Abys
- Here, if we give numbers as values for the variable (ex: age=25) we needn't provide them under double or single quotes as they give the same output but as for texts we should use "" or ''.
age = 25 print(age) 25 age = "25" print(age) 25 name = Abys print(name) Traceback (most recent call last): File "./prog.py", line 4, in <module> NameError: name 'Abys' is not defined </module>
- That's the reason for this rule. Hope it's clear.,
3. Printing Multiple Items :
We can print multiple items by separating them with commas while python adds space between each item.
Formatting strings with f strings is another sub topic where we insert variables directly into the string by prefixing it with an f and using curly braces {} around the variables.
let's see both,
name="Abys" age=17 city="Madurai" print("Name:",name , "Age:",age , "City:",city ,end=".") Name: Abys Age: 17 City: Madurai. print(f"Name:{name},Age:{age},City:{city}.") Name:Abys,Age:17,City:Madurai.
4.Concatenation of Strings :
- Here, we connect words using + operator.
w1="Sambar" w2="Vada" print(w1+" "+w2+"!") Sambar Vada!
Let's also see what is Printing Quotes inside Strings.
To print quotes inside a string, you can use either single or double quotes to enclose the string and the other type of quotes inside it.
w1="Sambar" w2="Vada" print("I love" , w1+" "+w2+"!") I love Sambar Vada! hobby = "Singing" print("My hobby is" , hobby) My hobby is Singing
5.Escape Sequences and Raw Strings to Ignore Escape Sequences :
- Escape sequences allows to include special characters in a string. For example, n adds a new line.
print("line1\nline2\nline3") line1 line2 line3
- r string is used as prefix which treats backslashes as literal characters.
print(r"C:\Users\Name") C:\Users\Name
6.Printing Results of Mathematical Expressions :
- We've already seen how to print numbers.
print(26) 26
- Now, we're going to print certain eqns.
print(5+5) 10 print(3-1) 2
that's how simple it is...
7.Printing Lists and Dictionaries :
- We can print entire lists and dictionaries.
fruits = ["apple", "banana", "cherry"] print(fruits) ['apple', 'banana', 'cherry']
8.Using sep and end Parameters :
The sep parameter changes the separator between items.
The end parameter changes the ending character.
print("Happy", "Holiday's", sep="-", end="!") Happy-Holiday's!
Let's see how to print the same in adjacent lines, here we use either escape sequences (n) or Multiline Strings.
Triple quotes allow you to print multiline strings easily.
print("""Happy Holiday's""") print("Happy\nHoliday's")
both gives same output as :
Happy Holiday's
9.Combining Strings and Variables :
Combining strings and variables by using + for simple cases or formatted strings for more complex scenarios.
For simple case:
colour = "purple" print("The colour of the bag is "+colour) The colour of the bag is purple
- For complex case :
temperature=22.5 print("The temperature is", str(temperature),"degree Celsius",end=".") The temperature is 22.5 degree Celsius.
10.Printing with .format() and Using print for Debugging:
- Use the .format() method for string formatting.
name="Abys" age=17 city="Madurai" print("Name:{}, Age:{}, City:{}".format(name,age,city)) Name:Abys, Age:17, City:Madurai
- We can use print to debug your code by printing variable values at different points.
def add(a, b): print(f"Adding {a} and {b}") return a + b result = add(1, 2) print("Result:", result) Adding 1 and 2 Result: 3
That's it.
These were the topics I learned in my 1st class.
At the beginning, I was confused by all the terms but as time went I got used to it just like I we first started to learn English.
Try it out yourself... as u begin to get the output., it's next level feeling.
I personally felt this;
"Nammalum Oru Aal Than Pola"...
.....
The above is the detailed content of My First Blog _Python. For more information, please follow other related articles on the PHP Chinese website!

This tutorial demonstrates how to use Python to process the statistical concept of Zipf's law and demonstrates the efficiency of Python's reading and sorting large text files when processing the law. You may be wondering what the term Zipf distribution means. To understand this term, we first need to define Zipf's law. Don't worry, I'll try to simplify the instructions. Zipf's Law Zipf's law simply means: in a large natural language corpus, the most frequently occurring words appear about twice as frequently as the second frequent words, three times as the third frequent words, four times as the fourth frequent words, and so on. Let's look at an example. If you look at the Brown corpus in American English, you will notice that the most frequent word is "th

This article explains how to use Beautiful Soup, a Python library, to parse HTML. It details common methods like find(), find_all(), select(), and get_text() for data extraction, handling of diverse HTML structures and errors, and alternatives (Sel

Dealing with noisy images is a common problem, especially with mobile phone or low-resolution camera photos. This tutorial explores image filtering techniques in Python using OpenCV to tackle this issue. Image Filtering: A Powerful Tool Image filter

PDF files are popular for their cross-platform compatibility, with content and layout consistent across operating systems, reading devices and software. However, unlike Python processing plain text files, PDF files are binary files with more complex structures and contain elements such as fonts, colors, and images. Fortunately, it is not difficult to process PDF files with Python's external modules. This article will use the PyPDF2 module to demonstrate how to open a PDF file, print a page, and extract text. For the creation and editing of PDF files, please refer to another tutorial from me. Preparation The core lies in using external module PyPDF2. First, install it using pip: pip is P

This tutorial demonstrates how to leverage Redis caching to boost the performance of Python applications, specifically within a Django framework. We'll cover Redis installation, Django configuration, and performance comparisons to highlight the bene

This article compares TensorFlow and PyTorch for deep learning. It details the steps involved: data preparation, model building, training, evaluation, and deployment. Key differences between the frameworks, particularly regarding computational grap

Python, a favorite for data science and processing, offers a rich ecosystem for high-performance computing. However, parallel programming in Python presents unique challenges. This tutorial explores these challenges, focusing on the Global Interprete

This tutorial demonstrates creating a custom pipeline data structure in Python 3, leveraging classes and operator overloading for enhanced functionality. The pipeline's flexibility lies in its ability to apply a series of functions to a data set, ge


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Mac version
God-level code editing software (SublimeText3)

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
