Posts

Beautiful soup in python

Hi there! Beautiful Soup  is a Python library for pulling data out of HTML and XML files. It works with your favorite parser to provide idiomatic ways of navigating, searching, and modifying the parse tree. It commonly saves programmers hours or days of work. These instructions illustrate all major features of Beautiful Soup 4, with examples. I show you what the library is good for, how it works, how to use it, how to make it do what you want, and what to do when it violates your expectations. The examples in this documentation should work the same way in Python 2.7 and Python 3.2. You might be looking for the documentation for  Beautiful Soup 3 . If so, you should know that Beautiful Soup 3 is no longer being developed and that support for it will be dropped on or after December 31, 2020. If you want to learn about the differences between Beautiful Soup 3 and Beautiful Soup 4, see  Porting code to BS4 .

Pyaudio library in python

Hi readers! It is a library of python used to discover audio files for a project by giving input by client. so that user can give voice as an input. With PyAudio, you can easily use Python to play and record audio on a variety of platforms, such as GNU/Linux, Microsoft Windows, and Apple Mac OS X.

Implenting the voice cmd on my project

Hi There! Today I am going to provide voice input to my project and that will done by the help of python library, as we know that python is having lots of library. So today I will be showing the client some features of my project. Pyalaudio and pyaudio library is helping out me for my voice input.

What is Alexa is!

Hi Readers! You’ve probably heard the name “Alexa.” You know, the name you call out when you want to interact with Amazon’s virtual assistant? Well, provided you own an Echo or some other Alexa-enabled device. Amazon’s assistant is a female voice that talks to you in a conversational manner, ready to help you with many tasks. She has been integrated into several of the company’s products and is starting to find her way into third-party devices, like  GE lamps  and the  Sonos One speaker . Amazon is also starting to put Alexa into  wearables , headphones, and all sorts of other gadgets. Alexa can perform a variety of simple tasks, like playing music, but you can also use Alexa in your smart home to dim the lights, lock the doors, adjust the thermostat, and control other smart home devices.

Python - Exceptions Handling

Hi there! Python provides two very important features to handle any unexpected error in your Python programs and to add debugging capabilities in them − Exception Handling  − This would be covered in this tutorial. Here is a list standard Exceptions available in Python:  Standard Exceptions . Assertions  − This would be covered in  Assertions in Python  tutorial. List of Standard Exceptions − Sr.No. Exception Name & Description 1 Exception Base class for all exceptions 2 StopIteration Raised when the next() method of an iterator does not point to any object. 3 SystemExit Raised by the sys.exit() function. 4 StandardError Base class for all built-in exceptions except StopIteration and SystemExit. 5 ArithmeticError Base class for all errors that occur for numeric calculation. 6 OverflowError Raised when a calculation exceeds maximum limit for a numeric type. 7 FloatingPointError Raised when a floating point cal...

Variable-length arguments in python

You may need to process a function for more arguments than you specified while defining the function. These arguments are called  variable-length  arguments and are not named in the function definition, unlike required and default arguments. Syntax for a function with non-keyword variable arguments is this − def functionname([formal_args,] *var_args_tuple ): "function_docstring" function_suite return [expression] An asterisk (*) is placed before the variable name that holds the values of all nonkeyword variable arguments. This tuple remains empty if no additional arguments are specified during the function call. Following is a simple example − Live Demo #!/usr/bin/python # Function definition is here def printinfo ( arg1 , * vartuple ): "This prints a variable passed arguments" print "Output is: " print arg1 for var in vartuple : print var return ; # Now you can call printinfo function printinfo (...

Pass by reference vs value

All parameters (arguments) in the Python language are passed by reference. It means if you change what a parameter refers to within a function, the change also reflects back in the calling function. For example − Live Demo #!/usr/bin/python # Function definition is here def changeme ( mylist ): "This changes a passed list into this function" mylist . append ([ 1 , 2 , 3 , 4 ]); print "Values inside the function: " , mylist return # Now you can call changeme function mylist = [ 10 , 20 , 30 ]; changeme ( mylist ); print "Values outside the function: " , mylist Here, we are maintaining reference of the passed object and appending values in the same object. So, this would produce the following result − Values inside the function: [10, 20, 30, [1, 2, 3, 4]] Values outside the function: [10, 20, 30, [1, 2, 3, 4]]

Function Arguments in python

Hi there! You can call a function by using the following types of formal arguments − Required arguments Keyword arguments Default arguments Variable-length arguments Required arguments Required arguments are the arguments passed to a function in correct positional order. Here, the number of arguments in the function call should match exactly with the function definition. To call the function  printme() , you definitely need to pass one argument, otherwise it gives a syntax error as follows − Live Demo #!/usr/bin/python # Function definition is here def printme ( str ): "This prints a passed string into this function" print str return ; # Now you can call printme function printme ()

Python - Functions

Hi Readers! A function is a block of organized, reusable code that is used to perform a single, related action. Functions provide better modularity for your application and a high degree of code reusing. As you already know, Python gives you many built-in functions like print(), etc. but you can also create your own functions. These functions are called  user-defined functions. Defining a Function You can define functions to provide the required functionality. Here are simple rules to define a function in Python. Function blocks begin with the keyword  def  followed by the function name and parentheses ( ( ) ). Any input parameters or arguments should be placed within these parentheses. You can also define parameters inside these parentheses. The first statement of a function can be an optional statement - the documentation string of the function or  docstring . The code block within every function starts with a colon (:) and is indented. The...

Python - Strings

Strings are amongst the most popular types in Python. We can create them simply by enclosing characters in quotes. Python treats single quotes the same as double quotes. Creating strings is as simple as assigning a value to a variable. For example − var1 = 'Hello World!' var2 = "Python Programming" Accessing Values in Strings Python does not support a character type; these are treated as strings of length one, thus also considered a substring. To access substrings, use the square brackets for slicing along with the index or indices to obtain your substring. For example − Live Demo #!/usr/bin/python var1 = 'Hello World!' var2 = "Python Programming" print "var1[0]: " , var1 [ 0 ] print "var2[1:5]: " , var2 [ 1 : 5 ] When the above code is executed, it produces the following result − var1[0]: H var2[1:5]: ytho Updating Strings You can "update" an existing string by (re)assigning a variabl...

Python - Numbers

Number data types store numeric values. They are immutable data types, means that changing the value of a number data type results in a newly allocated object. Number objects are created when you assign a value to them. For example − var1 = 1 var2 = 10 You can also delete the reference to a number object by using the  del  statement. The syntax of the del statement is − del var1[,var2[,var3[....,varN]]]] You can delete a single object or multiple objects by using the  del  statement. For example − del var del var_a, var_b

Python - Loops

Image
Decision making is anticipation of conditions occurring while execution of the program and specifying actions taken according to the conditions. Decision structures evaluate multiple expressions which produce TRUE or FALSE as outcome. You need to determine which action to take and which statements to execute if outcome is TRUE or FALSE otherwise. Following is the general form of a typical decision making structure found in most of the programming languages − Python programming language assumes any  non-zero  and  non-null  values as TRUE, and if it is either  zero  or  null , then it is assumed as FALSE value. Python programming language provides following types of decision making statements. Click the following links to check their detail.

Python Deciding factor

Image
Decision making is anticipation of conditions occurring while execution of the program and specifying actions taken according to the conditions. Decision structures evaluate multiple expressions which produce TRUE or FALSE as outcome. You need to determine which action to take and which statements to execute if outcome is TRUE or FALSE otherwise. Following is the general form of a typical decision making structure found in most of the programming languages − Python programming language assumes any  non-zero  and  non-null  values as TRUE, and if it is either  zero  or  null , then it is assumed as FALSE value.

Python Comparison Operators

These operators compare the values on either sides of them and decide the relation among them. They are also called Relational operators. Assume variable a holds 10 and variable b holds 20, then − [  Show Example  ] Operator Description Example == If the values of two operands are equal, then the condition becomes true. (a == b) is not true. != If values of two operands are not equal, then condition becomes true. (a != b) is true. <> If values of two operands are not equal, then condition becomes true. (a <> b) is true. This is similar to != operator. > If the value of left operand is greater than the value of right operand, then condition becomes true. (a > b) is not true. < If the value of left operand is less than the value of right operand, then condition becomes true. (a < b) is true. >= If the value of left operand is greater than or equal to the value of right operand, then condition becomes true. (a >= b) is not true. <= ...

Maching learning with CSDT IT SOLUTION

Python - Basic Operators

Operators are the constructs which can manipulate the value of operands. Consider the expression 4 + 5 = 9. Here, 4 and 5 are called operands and + is called operator. Types of Operator Python language supports the following types of operators. Arithmetic Operators Comparison (Relational) Operators Assignment Operators Logical Operators Bitwise Operators Membership Operators Identity Operators Let us have a look on all operators one by one.

Python Strings

Hi there! Strings in Python are identified as a contiguous set of characters represented in the quotation marks. Python allows for either pairs of single or double quotes. Subsets of strings can be taken using the slice operator ([ ] and [:] ) with indexes starting at 0 in the beginning of the string and working their way from -1 at the end. The plus (+) sign is the string concatenation operator and the asterisk (*) is the repetition operator.

Python - Variable Types

Hi Readers! Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. Based on the data type of a variable, the interpreter allocates memory and decides what can be stored in the reserved memory. Therefore, by assigning different data types to variables, you can store integers, decimals or characters in these variables. Assigning Values to Variables Python variables do not need explicit declaration to reserve memory space. The declaration happens automatically when you assign a value to a variable. The equal sign (=) is used to assign values to variables. The operand to the left of the = operator is the name of the variable and the operand to the right of the = operator is the value stored in the variable.

First Python Program

Hi Readers! Let us execute programs in different modes of programming. Interactive Mode Programming Invoking the interpreter without passing a script file as a parameter brings up the following prompt − $ python Python 2.4 . 3 (# 1 , Nov 11 2010 , 13 : 34 : 43 ) [ GCC 4.1 . 2 20080704 ( Red Hat 4.1 . 2 - 48 )] on linux2 Type "help" , "copyright" , "credits" or "license" for more information . >>> Type the following text at the Python prompt and press the Enter − >>> print "Hello, Python!" If you are running new version of Python, then you would need to use print statement with parenthesis as in  print ("Hello, Python!"); . However in Python version 2.4.3, this produces the following result − Hello, Python!

Characteristics of python

Hi there! Characteristics of Python Following are important characteristics of  Python Programming  − It supports functional and structured programming methods as well as OOP. It can be used as a scripting language or can be compiled to byte-code for building large applications. It provides very high-level dynamic data types and supports dynamic type checking. It supports automatic garbage collection. It can be easily integrated with C, C++, COM, ActiveX, CORBA, and Java. Hello World using Python. Just to give you a little excitement about Python, I'm going to give you a small conventional Python Hello World program, You can try it using Demo link.