Skip to main content

Python classes to Ammu

Python uses dynamic typing, meaning you can reassign variables to different data types. This makes Python very flexible in assigning data types; it differs from other languages that are statically typed. We can use a colon(:) to perform slicing which grabs everything up to a designated point. s='Hello world' print(s[:5])=Hello we can use two colons in a row and then a number specifying the frequency to grab elements. For example: s[::2] 'HloWrd' s[::3] 'Hlwl' s[::-1] 'dlroW olleH' .split() is a Built in string method used to split the string, by default it takes the blank spaces s='please split this function' s.split() ['please','split','this','function'] Split by a specific element by using that letter s.split('f') ['please split this', 'unction'] We can use the .format() method to add formatted objects to printed string statements. print('Insert another string with curly brackets: {}'.format('The inserted string')) 'Insert another string with curly brackets: The inserted string' print('Insert another {0} with curly brackets: {1}'.format('string','The inserted string')) Insert another string with curly brackets: The inserted string There are three ways to perform string formatting. •The oldest method involves placeholders using the modulo % character. print("I'm going to inject %s text here, and %s text here." %('some','more')) I'm going to inject some text here, and more text here. •An improved technique uses the .format() string method. 'String here {} then also {}'.format('something1','something2') print('The {2} {1} {0}'.format('fox','brown','quick')) print('First Object: {a}, Second Object: {b}, Third Object: {c}'.format(a=1,b='Two',c=12.3)) print('A %s saved is a %s earned.' %('penny','penny')) # vs. print('A {p} saved is a {p} earned.'.format(p='penny')) •The newest method, introduced with Python 3.6, uses formatted string literals, called f-strings name = 'Fred' print(f"He said his name is {name}.") Pass !r to get the string representation: print(f"He said his name is {name!r}") He said his name is 'Fred' Lists Earlier when discussing strings we introduced the concept of a sequence in Python. Lists can be thought of the most general version of a sequence in Python. Unlike strings, they are mutable, meaning the elements inside a list can be changed! my_list = [1,2,3] my_list = ['A string',23,100.232,'o'] my_list = ['one', 'two', 'three', 4, 5] You would have to reassign the list to make the change permanent. my_list = my_list + ['add new item permanently'] ['one', 'two', 'three', 4, 5, 'add new item permanently'] Use the append method to permanently add an item to the end of a list: list1.append('append me!') List1 = [1, 2, 3, 'append me!'] Use pop to "pop off" an item from the list. By default pop takes off the last index, but you can also specify which index to pop off. Nesting Lists A great feature of Python data structures is that they support nesting. This means we can have data structures within data structures. For example: A list inside a list. # Let's make three lists lst_1=[1,2,3] lst_2=[4,5,6] lst_3=[7,8,9] # Make a list of lists to form a matrix matrix = [lst_1,lst_2,lst_3] o/p matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] Dictionaries We've been learning about sequences in Python but now we're going to switch gears and learn about mappings in Python. If you're familiar with other languages you can think of these Dictionaries as hash tables. So what are mappings? Mappings are a collection of objects that are stored by a key, unlike a sequence that stored objects bytheir relative position. This is an important distinction, since mappings won't retain order since they have objects defined by a key. A Python dictionary consists of a key and then an associated value. That value can be almost any Python object. my_dict = {'key1':123,'key2':[12,23,33],'key3':['item0','item1','item2']} my_dict['key3'] = ['item0','item1','item2'] Tuples In Python tuples are very similar to lists, however, unlike lists they are immutable meaning they cannot be changed. You would use tuples to present things that shouldn't be changed, such as days of the week, or dates on a calendar. t = ('one',2) Because of this immutability, tuples can't grow. Once a tuple is made we cannot add to it. Sets Sets are an unordered collection of unique elements. We can construct them by using the set() function. Let's go ahead and make a set to see how it works list1 = [1,1,2,2,3,4,5,6,1,1] ; set(list1) = {1, 2, 3, 4, 5, 6} my_file1 = open('C:\\Users\\acer\\Desktop\\read.txt','a+') my_file1.write('\n This is a newly added line') my_file1.seek(0) print(my_file1.read()) if 1 > 0: print("hhh) print() elif 2>1: print else: print j = 0 for i in range(0,10): j = j+i print(j) list1 = [1,2,3,4,5] list1 = list1 + [sum(list1)] print(list1) for letter in 'This is a string.': print(letter) list2 = [(2,4),(6,8),(10,12)] t = 0 for t1 in list2: t = t + t1[0] print(t)

Comments

Popular posts from this blog

Lesson 57: Auto refresh the report in SSRS

                     How to Auto refresh the report in SSRS. Firstly create a datasource,dataset and select the required fields into the table/matrix. If you want to refresh the report frequently for every second you can change the Auto refresh as 1 in the properties of the report. If you want to change the color of a field after given period of time to change the expression of the color in properties as a follows and set the Auto refresh time to the required period of time in the report properties.

12th Day

Conditional statement in SSIS: same as ternary operator in C ** <condition>? <true>:<false> Eg: Gender=="M" ? "Male": "Female" Multicast Transformation : This t/r creates multiple copies of i/p data. it is useful because every time we need not to go to source. ** This will improve task performance. Aggregate Transformation : It is used to convert the detailed values into aggregated data by using Aggregate functions like sum,avg,max,min,count etc. ** It is Asynchronous transformation. Example: to the i/p data from source group by deptno and perform aggregate funcs. Conversion in SSIS ; * Conversion is very important because data from flat file, excel comes to transformations in the form of string(varchar) , so we cannot perform required operations so it require to convert data. 1) Directly at source level : ** Select flat file source, right click--> show advanced editor. ** Select i/p & o/p properties tab, ...

Lesson 60: Create folders and Data sources by Report Manager in SSRS

How to create folders and Data sources by using Report Manager in SSRS Firstly select the report manager URL from reporting services configuration and go to the reporting services home. Next click on New Folder option and create a folder for data sources, also create various folder for Data Sets and Reports. Now click on the Details view in order to move or delete multiple reports at once. For creating a New Data Source click on the New Data source in the Home and provide the connection string, also connect using a service account so that we can provide access to that service account and every one uses that service account for connecting to the database. Finally after adding/deploying a report, select manage from the dropdown and choose the correct datasource .