#kumar's python study notes
Explore tagged Tumblr posts
Text
Augmented assignment operators in python
Augmented assignment operators in Python combine addition and assignment in one statement. Instead of writing a = a + 1, you can write a += 1. This can make your code more concise and readable.
There are many augmented assignment operators in Python, including:
+= (addition)
-= (subtraction)
*= (multiplication)
/= (division)
//= (floor division)
%= (modulus)
**= (exponentiation)
&= (bitwise AND)
|= (bitwise OR)
^= (bitwise XOR)
<<= (bitwise left shift)
>>= (bitwise right shift)
Augmented assignment operators can be used with any Python variable, including numbers, strings, lists, and dictionaries.
Here are some examples of how to use augmented assignment operators in Python:
Python
# Add 1 to the variable a a = 1 a += 1 # Subtract 2 from the variable b b = 10 b -= 2 # Multiply 3 by the variable c c = 5 c *= 3 # Divide 4 by the variable d d = 10 d /= 4 # Floor divide 5 by the variable e e = 10 e //= 5 # Take the modulus of 6 by the variable f f = 10 f %= 6 # Raise 7 to the power of 2 g = 7 g **= 2 # Perform a bitwise AND operation on the variables h and i h = 10 i = 5 h &= i # Perform a bitwise OR operation on the variables j and k j = 10 k = 5 j |= k # Perform a bitwise XOR operation on the variables l and m l = 10 m = 5 l ^= m # Perform a bitwise left shift on the variable n by 1 bit n = 10 n <<= 1 # Perform a bitwise right shift on the variable o by 1 bit o = 10 o >>= 1
Augmented assignment operators can be a powerful tool for writing concise and readable Python code. They can be used with any Python variable, and they can be used to perform a variety of arithmetic and bitwise operations.
#programmer#studyblr#learning to code#codetober#python#kumar's python study notes#progblr#coding#programming#codeblr
75 notes
·
View notes
Text
Read on qt library from zetcode.com , they give easy tutorials on how to use C++ with making computer software
You all know the struggle :(
#programming#studyblr#learning to code#codetober#programmer#python#progblr#coding#kumar's python study notes#codeblr
89 notes
·
View notes
Text
80% off #From 0 to 1: Learn Python Programming – Easy as Pie – $10
A Python course for absolute beginners – this will take you to a fairly serious early intermediate level.
All Levels, – 10.5 hours, 55 lectures
Average rating 3.7/5 (3.7 (68 ratings) Instead of using a simple lifetime average, Udemy calculates a course’s star rating by considering a number of different factors such as the number of ratings, the age of ratings, and the likelihood of fraudulent ratings.)
Course requirements:
No prior programming experience is needed
The course will use a Python IDE (integrated development environment) called iPython from Anaconda. We will go through a step-by-step procedure on downloading and installing this IDE.
Course description:
What’s Covered:
Introductory Python: Functional language constructs; Python syntax; Lists, dictionaries, functions and function objects; Lambda functions; iterators, exceptions and file-handling Database operations: Just as much database knowledge as you need to do data manipulation in Python Auto-generating spreadsheets: Kill the drudgery of reporting tasks with xlsxwriter; automated reports that combine database operations with spreadsheet auto-generation Text processing and NLP: Python’s powerful tools for text processing – nltk and others. Website scraping using Beautiful Soup: Scrapers for the New York Times and Washington Post Machine Learning : Use sk-learn to apply machine learning techniques like KMeans clustering
Hundreds of lines of code with hundreds of lines of comments
Drill #1: Download a zip file from the National Stock Exchange of India; unzip and process to find the 3 most actively traded securities for the day Drill #2: Store stock-exchange time-series data for 3 years in a database. On-demand, generate a report with a time-series for a given stock ticker Drill #3: Scrape a news article URL and auto-summarize into 3 sentences Drill #4: Scrape newspapers and a blog and apply several machine learning techniques – classification and clustering to these
Talk to us!
A Note on the Python versions 2 and 3: The code-alongs in this class all use Python 2.7. Source code (with copious amounts of comments) is attached as a resource with all the code-alongs. The source code has been provided for both Python 2 and Python 3 wherever possible.
Mail us about anything – anything! – and we will always reply
Full details Pick up programming even if you have NO programming experience at all Write Python programs of moderate complexity Perform complicated text processing – splitting articles into sentences and words and doing things with them Work with files, including creating Excel spreadsheets and working with zip files Apply simple machine learning and natural language processing concepts such as classification, clustering and summarization Understand Object-Oriented Programming in a Python context
Full details Yep! Folks with zero programming experience looking to learn a new skill Machine Learning and Language Processing folks looking to apply concepts in a full-fledged programming language Yep! Computer Science students or software engineers with no experience in Java, but experience in Python, C++ or even C#. You might need to skip over some bits, but in general the class will still have new learning to offer you
Full details
Reviews:
“Excellent & Very Precise!! But Resource content is missing for this course.” (Sushil Kumar)
“This is a great python course. You will have the opportunity to dive into relevant topics. They are well selected. You will download files from websites, unzip them, read, process and finally write to Excel. You will work with a database. You will learn about objects , object oriented programming and how to use them. And you learn a lot of meaningful things about text analysis and applications of machine learning. I favor LoonyCorn – in my view, they are head and shoulders above the issues and convey the critical issues.” (H2m2)
“Like the presentation style, easy to understand even for kids. You can be up and running with python in no time.” (Sam)
About Instructor:
Loony Corn
Loonycorn is us, Janani Ravi, Vitthal Srinivasan, Swetha Kolalapudi and Navdeep Singh. Between the four of us, we have studied at Stanford, IIM Ahmedabad, the IITs and have spent years (decades, actually) working in tech, in the Bay Area, New York, Singapore and Bangalore. Janani: 7 years at Google (New York, Singapore); Studied at Stanford; also worked at Flipkart and Microsoft Vitthal: Also Google (Singapore) and studied at Stanford; Flipkart, Credit Suisse and INSEAD too Swetha: Early Flipkart employee, IIM Ahmedabad and IIT Madras alum Navdeep: longtime Flipkart employee too, and IIT Guwahati alum We think we might have hit upon a neat way of teaching complicated tech courses in a funny, practical, engaging way, which is why we are so excited to be here on Udemy! We hope you will try our offerings, and think you’ll like them
Instructor Other Courses:
Learn by Example: JUnit Loony Corn, A 4-person team;ex-Google; Stanford, IIM Ahmedabad, IIT (0) $10 $20 Under the Hood: How Cars Work 25 Famous Experiments …………………………………………………………… Loony Corn coupons Development course coupon Udemy Development course coupon Programming Languages course coupon Udemy Programming Languages course coupon From 0 to 1: Learn Python Programming – Easy as Pie From 0 to 1: Learn Python Programming – Easy as Pie course coupon From 0 to 1: Learn Python Programming – Easy as Pie coupon coupons
The post 80% off #From 0 to 1: Learn Python Programming – Easy as Pie – $10 appeared first on Course Tag.
from Course Tag http://coursetag.com/udemy/coupon/80-off-from-0-to-1-learn-python-programming-easy-as-pie-10/ from Course Tag https://coursetagcom.tumblr.com/post/158184091898
0 notes
Text
Python Operator Basics
x or y - Logical or (y is evaluated only if x is false)
lambda args: expression - Anonymous functions (I don't know what the fuck is this, I have to look into it)
x and y - Logical and (Y is evaluated only if x is true)
<, <=, >, >=, ==, <>, != - comparison tests
is, is not - identity tests
in, in not - membership tests
x | y - bitwise or (I still have to learn bitwise operation)
x^y - bitwise exclusive or (I read this somewhere now I don't remember it)
x&y - bitwise and (again I have to read bitwise operations)
x<;<y, x>>y - shift x left or right by y bits
x+y, x-y - addition/concatenation , subtraction
x*y, x/y, x%y - multiplication/repetition, division, remainder/format (i don't know what format is this? should ask bard)
-x, +x, ~x - unary negation, identity(what identity?), bitwise complement (complement?)
x[i], x[i:j], x.y, x(...) - indexing, slicing, qualification (i think its member access), function call
(...), [...], {...} `...` - Tuple , list dictionary , conversion to string
#kumar's python study notes#study notes#study blog#coding#programmer#programming#python#studyblr#codeblr#progblr
67 notes
·
View notes
Text
Lists in python
Lists in Python are a type of sequence data type. They are mutable, meaning that they can be changed after they are created. Lists can store elements of any type, including strings, integers, floats, and even other lists.
Lists are represented by square brackets ([]) and contain elements separated by commas. For example, the following code creates a list of strings:
Python
my_list = ["apple", "banana", "cherry"]
Lists can be accessed using indices, which start at 0. For example, the following code prints the first element of the list my_list:
Python
print(my_list[0])
Output:
apple
Lists can also be sliced, which allows you to extract a subset of the list. For example, the following code prints a slice of the list my_list that contains the first two elements:
Python
print(my_list[0:2])
Output:
['apple', 'banana']
Lists can be modified by adding, removing, or changing elements. For example, the following code adds an element to the end of the list my_list:
Python
my_list.append("orange")
The following code removes the first element of the list my_list:
Python
my_list.pop(0)
The following code changes the second element of the list my_list:
Python
my_list[1] = "pear"
Lists can be used to perform a variety of tasks, such as storing data, iterating over data, and performing data analysis.
Here are some examples of how to use lists in Python:
Python
# Create a list of numbers numbers = [1, 2, 3, 4, 5] # Print the list print(numbers) # Add an element to the list numbers.append(6) # Remove an element from the list numbers.pop(0) # Sort the list numbers.sort() # Reverse the list numbers.reverse() # Iterate over the list for number in numbers: print(numbers)
Output:
[1, 2, 3, 4, 5] [2, 3, 4, 5, 6] [3, 4, 5, 6] [6, 5, 4, 3] 3 4 5 6
Lists are a powerful tool for working with collections of data in Python. They can be used to perform a variety of tasks, such as storing data, iterating over data, and performing data analysis.
#progblr#studyblr#learning to code#codetober#programmer#kumar's python study notes#python#coding#programming#codeblr
50 notes
·
View notes
Text
The split() function in python
The split() method in Python is used to split a string into a list of strings. It takes an optional separator argument, which is the delimiter that is used to split the string. If the separator is not specified, the string is split at any whitespace characters.
The syntax of the split() method is as follows:
Python
string_name.split(separator)
where:
string_name is the string object that is calling the split() method.
separator is the string that is being used as the separator.
For example, the following code splits the string my_string at the first occurrence of the " character:
Python
my_string = "This is a string with a \"quote\" in it." parts = my_string.split("\"") print(parts)
This code will print the following output:
['This is a string with a ', 'quote', ' in it.']
Here are some additional examples of how to use the split() method:
Python
my_string = "This is a string with multiple separators: -_--_-" parts = my_string.split("--") print(parts)
This code will print the following output:
['This is a string with multiple separators: ', '_', '_-']
Python
my_string = "This is a string without a separator." parts = my_string.split("@") print(parts)
This code will print the following output:
['This is a string without a separator.']
The split() method is a very versatile tool that can be used to split strings into lists of strings in a variety of ways. It is commonly used for tasks such as parsing text files, extracting data from strings, and validating user input.
#programmer#studyblr#learning to code#python#kumar's python study notes#codetober#progblr#coding#codeblr#programming
39 notes
·
View notes
Text
The partition method in python
The partition() method in Python is used to split a string into three parts at the first occurrence of a specified separator string. It returns a tuple containing three elements: the part of the string before the separator, the separator itself, and the part of the string after the separator.
If the separator is not found in the string, the tuple will contain the original string and two empty strings.
The syntax of the partition() method is as follows:
Python
string_name.partition(separator)
where:
string_name is the string object that is calling the partition() method.
separator is the string that is being used as the separator.
For example, the following code partitions the string my_string at the first occurrence of the " character:
Python
my_string = "This is a string with a \"quote\" in it." parts = my_string.partition("\"") print(parts)
This code will print the following output:
('This is a string with a ', '"', 'quote\" in it.')
Here are some additional examples of how to use the partition() method:
Python
my_string = "This is a string with multiple separators: -_--_-" parts = my_string.partition("--") print(parts)
This code will print the following output:
('This is a string with multiple separators: -_', '--', '_-')
Python
my_string = "This is a string without a separator." parts = my_string.partition("@") print(parts)
This code will print the following output:
('This is a string without a separator.', '@', '')
#programmer#studyblr#learning to code#python#kumar's python study notes#progblr#coding#codeblr#programming
46 notes
·
View notes
Text
Interning in python, what is it.
Python uses a technique called interning to store small and unchanging values in memory. Interning means that Python only stores one copy of an object in memory, even if multiple variables reference it. This saves memory and improves performance.
Integers are one of the types of objects that are interned in Python. This means that all integer objects from -5 to 256 are stored in the same memory location. This is why the integer object is the same in memory for the following code:
Python
a = 10 b = 10 print(a is b)
Output:
True
However, interning is not applied to all objects in Python. For example, lists and other more complex data types are not interned. This means that every time you create a new list, a new memory space is allocated for it, even if the list contains the same elements as an existing list.
It is important to note that interning can be disabled in Python. To do this, you can set the sys.intern variable to False. However, this is not recommended, as it can lead to performance problems.
Here are some additional benefits of interning:
It reduces the number of objects that need to be garbage collected.
It makes it easier to compare objects for equality.
It can improve the performance of operations that involve objects, such as hashing and object lookups.
Overall, interning is a powerful technique that Python uses to improve memory usage and performance.
#programmer#studyblr#learning to code#codetober#python#progblr#coding#kumar's python study notes#programming#codeblr
23 notes
·
View notes
Text
How to do a summation of a series in python (an example)
Here is an example of summation of series in Python:
Python
def summation_of_series(series): """Calculates the summation of a series of numbers. Args: series: A list of numbers. Returns: The summation of the series. """ sum = 0 for number in series: sum += number return sum # Example usage: series = [1, 2, 3, 4, 5] sum = summation_of_series(series) print(sum)
Output:
15
This function can be used to calculate the summation of any series of numbers, regardless of the length of the series.
Here is another example of summation of series in Python, using the numpy library:
Python
import numpy as np def summation_of_series_numpy(series): """Calculates the summation of a series of numbers using the `numpy` library. Args: series: A numpy array of numbers. Returns: The summation of the series. """ sum = np.sum(series) return sum # Example usage: series = np.array([1, 2, 3, 4, 5]) sum = summation_of_series_numpy(series) print(sum)
Output:
15
This function is similar to the previous function, but it uses the numpy library to calculate the summation of the series. This can be more efficient for large series of numbers.
I hope this helps!
#programmer#studyblr#learning to code#python#progblr#coding#kumar's python study notes#codeblr#programming
22 notes
·
View notes
Text
Keyword arguments in python
Keyword arguments in Python are arguments that are passed to a function by name. This is in contrast to positional arguments, which are passed to a function in the order that they are defined in the function definition.
Keyword arguments are useful because they allow you to specify the exact values that you want to pass to a function, without having to worry about the order of the arguments. This can be useful for functions that have a large number of arguments, or for functions where the order of the arguments is not important.
To pass a keyword argument to a function, you simply need to specify the name of the argument, followed by an equal sign (=) and the value of the argument. For example, the following code passes the name keyword argument to the print() function:
Python
print(name="Alice")
This code is equivalent to the following code:
Python
print(name="Alice", end="")
The only difference is that the keyword argument is more explicit and easier to read.
Keyword arguments can also be used to pass default values to function arguments. For example, the following function definition specifies a default value of 10 for the count keyword argument:
Python
def my_function(count=10): """Prints the number `count` times. Args: count: The number of times to print the number. """ for i in range(count): print(i)
This function can then be called with or without the count keyword argument. If the count keyword argument is not specified, the default value of 10 will be used. For example, the following code is equivalent:
Python
my_function() my_function(count=5)
Keyword arguments are a powerful tool that can be used to make your Python code more readable and maintainable. I hope this helps!
#programmer#studyblr#learning to code#codetober#python#progblr#coding#codeblr#programming#kumar's python study notes
15 notes
·
View notes
Text
Difference between identity operator and equality operator in python
Identity operators compare the objects themselves, while equality operators compare the values of the objects.
Identity operators
is: Returns True if the two objects are the same object in memory, and False otherwise.
is not: Returns True if the two objects are not the same object in memory, and False otherwise.
Equality operators
==: Returns True if the two objects have the same value, and False otherwise.
!=: Returns True if the two objects do not have the same value, and False otherwise.
Contrasting example:
Python
>>> a = 10 >>> b = 10 >>> a is b True >>> a == b True >>> c = [1, 2, 3] >>> d = [1, 2, 3] >>> c is d False >>> c == d True
In the first example, the variables a and b both reference the same integer object in memory, so a is b returns True. Additionally, the two integers have the same value, so a == b also returns True.
In the second example, the variables c and d reference two different list objects in memory, so c is d returns False. However, the two lists have the same contents, so c == d returns True.
Conclusion:
Identity operators should be used to compare objects themselves, while equality operators should be used to compare the values of the objects.
#programmer#studyblr#learning to code#codetober#python#progblr#kumar's python study notes#codeblr#coding#programming
14 notes
·
View notes
Text
Difference between index() and find() in python
The main difference between the index() and find() functions in Python is that the index() function raises a ValueError exception if the substring is not found, while the find() function returns -1.
Here is a table that summarizes the differences between the two functions:
Function
Description
index()
Returns the index of the first occurrence of the substring in the string. Raises a ValueError exception if the substring is not found.
find()
Returns the index of the first occurrence of the substring in the string. Returns -1 if the substring is not found.
The index() function is typically used when you need to ensure that the substring is present in the string before performing an operation. For example, you might use the index() function to extract a substring from a string, or to search for a specific pattern in a string.
The find() function is typically used when you want to check if a substring is present in a string, but you don't need to raise an exception if it's not found. For example, you might use the find() function to validate user input, or to determine the position of a specific character in a string.
Here are some examples of how to use the index() and find() functions:
Python
# Use the `index()` function to extract a substring from a string: my_string = "hello, world!" substring = "world" index = my_string.index(substring) world_substring = my_string[index:index + len(substring)] print(world_substring)
Output:
world
Python
# Use the `find()` function to check if a substring is present in a string: my_string = "hello, world!" substring = "x" index = my_string.find(substring) if index != -1: print("The substring 'x' is present in the string.") else: print("The substring 'x' is not present in the string.")
Output:
The substring 'x' is not present in the string.
I hope this helps!
#programmer#studyblr#learning to code#python#kumar's python study notes#codeblr#coding#programming#progblr
3 notes
·
View notes
Text
Slicing strings in python
Slicing in Python strings is the process of extracting a substring from a string. You can use the slice operator ([:]) to specify the start and end indices of the substring. The slice operator is inclusive at the start, but exclusive at the end.
For example, the following code extracts the substring "world!" from the string "Hello, world!":
Python
my_string = "Hello, world!" world = my_string[7:] print(world)
Output:
world!
You can also use the slice operator to extract a substring from a string starting at the beginning or ending at the end of the string. For example, the following code extracts the substring "Hello" from the string "Hello, world!":
Python
my_string = "Hello, world!" hello = my_string[:5] print(hello)
Output:
Hello
You can also use the slice operator to extract a substring from a string with a step size. The step size specifies how often to skip characters in the string. For example, the following code extracts the substring "Hlowrd" from the string "Hello, world!" with a step size of 2:
Python
my_string = "Hello, world!" hlowrd = my_string[::2] print(hlowrd)
Output:
Hlowrd
Slicing is a powerful tool for extracting substrings from strings in Python. It is used in many different Python libraries and applications.
#programmer#studyblr#learning to code#progblr#python#kumar's python study notes#codeblr#coding#programming
1 note
·
View note
Text
Formatting strings in python
String formatting in Python is the process of inserting values into a string. This can be done using the format() method or f-strings.
Using the format() method
The format() method takes a format string and a number of arguments and returns a formatted string. The format string is a string that contains placeholder markers, which are indicated by curly braces ({}). The arguments are the values that will be inserted into the placeholder markers.
For example, the following code formats the string "Hello, {}!" to include the name Alice:
Python
my_string = "Hello, {}!" formatted_string = my_string.format("Alice") print(formatted_string)
Output:
Hello, Alice!
You can also use the format() method to insert more complex expressions into a string. For example, the following code formats the string "The number {} is even." to include the number 10:
Python
my_string = "The number {} is even." formatted_string = my_string.format(10 % 2 == 0) print(formatted_string)
Output:
The number 10 is even.
Using f-strings
F-strings are a newer way to format strings in Python. They are easier to read and write than the format() method.
To create an f-string, prefix the string with an f character. Inside the string, you can write Python expressions between curly braces ({}). The expressions will be evaluated and the results will be inserted into the string.
For example, the following code is equivalent to the previous example that uses the format() method:
Python
my_string = f"The number {10 % 2 == 0} is even." print(my_string)
Output:
The number 10 is even.
F-strings are a powerful and concise way to format strings in Python.
#programmer#studyblr#learning to code#progblr#python#coding#codeblr#programming#kumar's python study notes
0 notes
Text
How to repeat strings in python
Repetition in strings in Python can be done using the asterisk (*) operator. The asterisk operator is used to multiply the string a certain number of times. For example, the following code prints the string "Hello, world!" five times:
Python
print("Hello, world!" * 5)
Output:
Hello, world!Hello, world!Hello, world!Hello, world!Hello, world!
You can also use the asterisk operator to repeat a substring within a string. For example, the following code prints the substring "abc" five times:
Python
print("abc" * 5)
Output:
abcabcabcabcabc
Repetition in strings can be used for a variety of purposes, such as:
Creating borders and frames
Generating patterns
Repeating text for emphasis
Creating dynamic content
Here is an example of how to use repetition in strings to create a border:
Python
print("+" * 20)
Output:
++++++++++++++++++++
Here is an example of how to use repetition in strings to generate a pattern:
Python
print("*" * 5) print("**" * 5) print("***" * 5) print("****" * 5) print("*****" * 5)
Output:
***** ****** ******* ******** *********
Here is an example of how to use repetition in strings to repeat text for emphasis:
Python
print("Important message: " * 3 + "Please read carefully.")
Output:
Important message: Important message: Important message: Please read carefully.
Here is an example of how to use repetition in strings to create dynamic content:
Python
name = "Alice" print("Hello, " + name * 5 + "!")
Output:
Hello, AliceAliceAliceAliceAlice!
Repetition in strings is a powerful tool that can be used to create a variety of effects.
#programmer#studyblr#learning to code#python#progblr#kumar's python study notes#coding#codeblr#programming
0 notes
Text
How to traverse a string python
There are two main ways to traverse a string in Python:
Using a for loop
Using a while loop
Using a for loop
To traverse a string using a for loop, you can use the following code:
Python
my_string = "Hello, world!" for character in my_string: print(character)
This code will print each character in the string to the console.
Using a while loop
To traverse a string using a while loop, you can use the following code:
Python
my_string = "Hello, world!" index = 0 while index < len(my_string): print(my_string[index]) index += 1
This code will also print each character in the string to the console.
Which method you use to traverse a string is up to you. The for loop is generally more concise and easier to read, but the while loop can be more flexible in some cases.
Here is an example of how to use a for loop to traverse a string and reverse the order of the characters:
Python
my_string = "Hello, world!" reversed_string = "" for character in my_string[::-1]: reversed_string += character print(reversed_string)
Output:
!dlrow ,olleH
Here is an example of how to use a while loop to traverse a string and find the index of a specific character:
Python
my_string = "Hello, world!" target_character = "o" index = 0 while index < len(my_string): if my_string[index] == target_character: break index += 1 if index < len(my_string): print("The index of the character '{}' is {}.".format(target_character, index)) else: print("The character '{}' is not found in the string.".format(target_character))
Output:
The index of the character 'o' is 4.
Traversing strings is a common task in Python. By learning how to traverse strings, you will be able to write more powerful and flexible code.
#programmer#studyblr#learning to code#progblr#python#kumar's python study notes#codeblr#coding#programming
0 notes