Skip to content

subhashgowda/Python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python

Learn python easily with me


Data types

PYTHON

From creator of Python

“high-level programming language, and its core design philosophy is all about code readability and a syntax which allows programmers to express concepts in a few lines of code.”

1_7EUX9QIjq2x1JyFKcjhXsA

Python Data Types

In Python, common data types are float (floating point), int (integer), str (string), bool (Boolean), list, and dict (dictionary).

  • float - used for real numbers.
  • int - used for integers.
  • str - used for texts. We can define strings using single quotes'value', double quotes"value", or triple quotes"""value""". The triple quoted strings can be on multiple lines, the new lines will be included in the value of the variable. They’re also used for writing function documentation.
  • bool - used for truthy values. Useful to perform a filtering operation on a data.
  • list - used to store a collection of values.
  • dict - used to store a key-values pairs.

Here we can look at some examples with creating a floating points, intergers, strings and booleans in Python.```

Screenshot (265)

Python Lists

  • Python list is a basic sequence type.
  • One list can contain values of any type.
  • It is possible that one list contains another nested lists for its values.
  • It’s not commonly used, but you can have a list with a mix of Python types. You can create a new one using square brackets like this:

fruits = ["pineapple", "apple", "lemon", "strawberry", "orange", "kiwi"]

Subsetting Lists

  • Indexes are used to get element or elements from the list.

  • In Python, the indexes start from 0. Therefore, the first element in the list will have an index 0.

  • Negative indexes are also used to access elements.The last element in the list will have an index -1, the one before the last one will have an index -2 and so on.

  • list slicing which can be used to get multiple elements from a list. We can use it like this: sliceable[start_index:end_index:step].

    • The start_index is the beginning index of the slice, the element at this index will be included to the result, the default value is 0.
    • The end_index is the end index of the slice, the element at this index will not be included to the result, the default value will be the length of the list. Also, the default value can be - length of the list -1 if the step is negative. If you skip this, you will get all the elements from the start index to the end.
    • The step is the amount by which the index increases, the default value is 1. If we set a negative value for the step, we’ll move backward.

Screenshot (267)



Python code to convert speech to text.

  
import speech_recognition as sr
r = sr.Recognizer()
with sr.Microphone() as source:
    print('Speak Anything')
    audio = r.listen(source)
    
    try:
        text = r.recognize_google(audio)
        print('you said : {}'.format(text))
    except:
        print('Sorry')       

Python code to convert text to speech.

"""
@author: subha
"""

import pyttsx3

engine = pyttsx3.init()
say = input('enter')
engine.say(say)
engine.say("Im bored")

engine.runAndWait()

Python code to create multiple excel sheets with incremental sheet names

"""
@author: subha
"""
#Create multiple excel sheets
import openpyxl

wb = openpyxl.Workbook()
sheet = wb.active
for i in range(1,10):
        if i!=0:
                 j=i+2
                 
                
                 wb.create_sheet(index = j, title = 'HDD %d' %i)
                 wb.save(filename = "demo.xlsx")

About

Learn python easily

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages