Featured Post

পরিত্যাক্ত শহর হাওড়া

  তৃতীয় বিশ্বযুদ্ধ শেষ হবার পরে অনেক কিছুর বদল হয়েছে। এখন পৃথিবী সূর্যের চারিদিকে ঘরে না বরং সূর্য সহ অন্য সকল গ্রহকে কৃত্রিম ভাবে পৃথিবীর চারিদিকে ঘোরানো হচ্ছে।সেই সময় এর কথা মৃত নগর হাওড়া। তৃতীয় বিশযুদ্ধের সময় চিনা বোমা বর্ষণের ভয়ে সমস্ত নগরবাসী পলায়ন করেছিলো। ডাঃ কেসি পাল এর নেতৃত্বে ওরা মোট চারজন মানে রমেশ, সুমিত ও মাধব সেই রহস্যময় তেজস্ক্রিয় উৎসের সন্ধানে এসেছে। সকাল এগারোটা ঝোঁপ ঝাড় ভর্তি গলি রাস্তা যেখানে বহুবছর কোনো লোকের পা পড়েনি। রাস্তার ধারে ভগ্নপ্রায় লতা পাতা দ্বারা আচ্ছাদিত হয়ে সারি সারি বাড়ি দাড়িয়ে আছে। মাঝে মাঝে কিছু বন্য পাখির ডাক শোনা যাচ্ছে। ঝিঁঝিঁ পোকার ডাকে ওদের পায়ের শব্দ ঢাকা পড়ে গেলেও ওদের যাবার রাস্তার সামনে দিয়ে কি যেনো সর সর করে রাস্তার দুদিকে নেমে যাচ্ছে।ওদের পায়ের কম্পনে রাস্তার উপর ঘাস থেকে ছোটো ছোট পোকা উড়ছে। বাতাসে ঘেঁটু ফুলের গন্ধে ছেয়ে আছে। কিছুদিন আগে ইসরোর এক কৃত্রিম উপগ্রহ ছবিতে এই পরিত্যাক্ত মৃত নগরীর উপর এক রহস্যময় আলোর সন্ধান জানা যায়। তারপর অন্য স্যাটেলাইট এর স্পেকট্রোস্কোপি বিশ্লেষণ এর মাধ্যমে জানা যায় ঐ আলোক কোনো তেজস্

Puthon3

Python3 Tutorials

Introduction


The Simplest High Level Programming Language is Python. Python is a scripting Language so it does not need any kind compile.There is generally two types major python version Python2 and Python3 but Python3 is latest and more usefull.There are lot of Python3 Version .I will recommend to install Python version-3.8.10.You also can test your python script in online by using Google Colab.

Python3 Installation

First go to Python version-3.8.10 official link and download the python installer as your system i.e. Windows,Mac etc 32bit or 64 bit etc.Open Command Prompt(Windows) or Terminal(Mac/Linux) and type python or python3 and enter will show python interpreter with version if no python showing then add python path from your system settings.Now you have created your python envirionment for further programming. If you wish you don't want to install python in your machine then you may try Google Colab where you need to create a new account and create a google colab envirionment and there you can write your python file as well as run on it.

Hello World Program

The First Hello World Program is :

The Output look like:

You can run the program on Command Prompt/Terminal :

Or You can run the program by writing a file with extension .py

Or You can write or run on Google Colab


Python Variables


🔵There are many variable types in Python

  • booleans(Which have values True, Flase)
  • integers(Which have values 1,100,532 etc)
  • floats(Which have values 3.1441,3.02,976.65 etc)
  • strings(Which have values "this is a string", "love","a" etc)

To check a variable type just type 'type(variable)' in the interpreter.

we can change boolean to integer by wraping int()

                  
                      >>> int(True)
                      1
                      >>> int(False)
                      0
                      >>>
                  
            

Similarly we can change integer into boolean by wraping 'bol' and vice varsa by wraping 'int'

                  
                      >>> bool(1)
                      True
                      >>> bool(0)
                      False
                      >>>type(True)
                      <class 'bool'>
                      >>>int(True)
                      0
                      >>>
                  
            

Hash (#) symbol is using for comment i.e. the texts after # in a line ignore by python

                  
                      >>> #Nothing will happened
                      >>>
                  
            

Similarly we can change integer into float by wraping 'float', vice varsa by wraping 'int'

                  
                      >>> float(10)
                      10.0
                      >>> float(32)
                      32.0
                      >>> type(32.0)
                      <class 'float'>
                      >>> int(65.89) #returning integer value only not approximate
                      65
                      >>>
                  
            

Similarly we can change all variable type into 'string' type variable by wraping string and sometimes vicevarsa for correct data

                  
                      >>> str(10)
                      "10"
                      >>> str(True)
                      "True"
                      >>> str(45.86)
                      "45.86"
                      >>> type('45.86')
                      <class 'str'>
                      >>> int('65.89')
                      65
                      >>> float('65.89')
                      65.89
                      >>> int("76gh") #It will show error as 76 as well as gh present
                      Traceback (most recent call last):
                        File "", line 1, in 
                      ValueError: invalid literal for int() with base 10: '76gh'
                      >>>
                  
            

Manipulation with string variables

                  
                      >>>a="This is a string variable" #set a variable 'a' with a string value =  "This is a string variable"
                      >>>type(a)
                      >>><class 'str'>
                      >>>a #printing value of a
                      >>>"This is a string variable"
                      >>>print(a) #another way to print the value of a
                      >>>"This is a string variable"
                      >>>len(a) #print length of string
                      >>>25
                      >>>#25 means 25 character including space 
                      >>>#The first character 'T' of the string has index 0
                      >>>a[0]
                      >>>'T"
                      >>>The last character index is 25-1=24 as first index start from zero so last character index always be one less than total length of the string
                      >>>a[24]
                      >>>'e'
                      >>>a[2:4] #This will print character from index position 2(third character) to index position 4(third character)
                      >>>'is'
                      >>>a[0:24:2] #Skipping 2,4,6,8,10,12,14,16,18,20,22 characters
                      >>>'Ti sasrn aib'
                  
            

Escape with \

'\n' creates new line, '\t' creates a tab, '\\' creates special character with '\'

                  
                      >>>s = "This is a line.\nThis is a new line."
                      >>> print(a)
                      This is a line.
                      This is a new line.
                      >>> print("\tabc")
                      	abc
                      >>> print("\'")
                      "'"
                      >>> print("\"")
                      >>> """
                  
            

Addition of string by "+" and repeat string by "*"

                  
                      >>>s = "Abc" + "def"
                      >>> print(s)
                      "Abcdef"
                      >>> print("abc" *3)
                      "abcabcabc"
                  
            

String split with split() gives a list

                  
                      >>> a = "The forest have lion,tiger,deer,cow etc animals"
                      >>> a.split(",")
                      ['The forest have lion', 'tiger', 'deer', 'cow etc animals']
                      >>>
                  
            

String join with join() gives a new string from list

                  
                  	  >>> a = "The forest have lion,tiger,deer,cow etc animals"
                      >>> b =  a.split(",")
                      >>> c = ",".join(b)
                      >>> c
                      >>> "The forest have lion,tiger,deer,cow etc animals"
                  
            

More useful methods to manipulate strings

                  
                  	 >>> test = "How are you?Do you have a boat?....If yes please use it."
                     >>> test.strip(".")
                     >>> 'How are you?Do you have a boat?....If yes please use it'
                     >>> test.capitalize()
                     >>> 'How are you?do you have a boat?....if yes please use it.'
                     >>> test.title()
                     >>> 'How Are You?Do You Have A Boat?....If Yes Please Use It.'
                     >>> test.upper()
                     >>> 'HOW ARE YOU?DO YOU HAVE A BOAT?....IF YES PLEASE USE IT.'
                     >>> test.lower()
                     >>> 'how are you?do you have a boat?....if yes please use it.'
                     >>> test.swapcase()
					 'hOW ARE YOU?dO YOU HAVE A BOAT?....iF YES PLEASE USE IT.'
                     >>> test.replace("boat", "cycle")
                     'How are you?Do you have a cycle?....If yes please use it.'
                     >>> setup = "a marmoset goes into a bar..."
                     >>> setup.replace("a", "famous", 100) #change upto 100th 
                     >>> 'a famous marmoset goes into a famous bar...'
                     >>> setup.startswith("a")
                     >>> True
                     >>> setup.endswith("bar")
                     False
                     >>> setup.find("bar")
                     23
                     >>> setup.rfind("a")
                     24
                     >>> setup.count("a")
                     4
                     >>> setup.isalnum()
                     False
                     
                  
            

Exercise

Q1. Creates a simple Calculator. hint: take input by a=input("Please enter your value:")


Lists, Tuples, Dictionarirs, and Sets


Python Lists data

The list can be created by third bracket i.e. [] .The elements of a list can be any kind variables i.e integer, float,boolean,string even another list, tuples and set can be also an element of a list.The first item of a list indexed by zero and so on.

                  
                  	  >>> empty_list = []
                      >>> week_days = ["Sunday","Monday","Tuesday","Wednusday","Thursday","Friday","Saturday"]
                      >>> type(week_days)
                      >>> <tclass 'list'>
                      >>> week_days[0]
                      >>> 'Sunday'
                      >>> len(week_days)
                      >>> 7
                      
                  
            

List of List

                  
                  	  >>> empty_list = []
                      >>> week_days = ["Sunday","Monday","Tuesday","Wednusday","Thursday","Friday","Saturday"]
                      >>> rand_list = "abc-def-ghi-jkl".split("-")
                      >>> rand_list
                      >>> ['abc', 'def', 'ghi', 'jkl']
                      >>> new_list = [week_days,rand_list]
                      >>> new_list
                      >>> [['Sunday', 'Monday', 'Tuesday', 'Wednusday', 'Thursday', 'Friday', 'Saturday'], ['abc', 'def', 'ghi', 'jkl']]
                      >>> new_list[1]
                      >>> ['abc', 'def', 'ghi', 'jkl']
					  
                      
                  
            

Popular posts from this blog

Some Funny Mathematical Questions

পৃথিবীর কোনো এক আদিম সকাল