Login using Social Account
Login using your credentials
We can search in the file line by line or by creating a single string for the whole content of the file.
check = 0 with open("/cxldata/python_sample_file") as f: for line in f: if(line.startswith('w')): check = check + 1
startswith function checks if the string is starting with the argument mentioned in the brackets.
startswith
Basically, here were searching for the lines in the file which are starting with 'w'.
'w'
Can you tell the value of check after the above code is executed?
Taking you to the next exercise in seconds...
Stay here Next Exercise
Want to create exercises like this yourself? Click here.
Answer is not availble for this assesment
Note - Having trouble with the assessment engine? Follow the steps listed here
Go Back to the Course
1 Getting Started - Setting up the environment
2 Introduction to Programming and Python
3 Why Programming?
4 A Quick Introduction
5 Who are programmers
6 Computer consists of
7 A code/program/software is
8 All the processing in a computer is done in the
9 All the information which is required for the execution of an instruction is stored in the
10 What do we use to interact with the computer
11 Main memory content is lost on reboot
12 Main memory is slower than secondary memory
13 Why do people use Python Programming language ?
14 Execution speed of Python is faster than C or C++
15 What all things you can do using Python ?
16 A program flow or program steps can be of either sequence, conditional or repeated ?
17 Which statement is used to take input in Python
18 Which statement is used show output in Python
19 Python Programming - Assigning value to a variable
20 Python as a Calculator
21 Python Programming - Integer Division
22 Order of Operations in Python
23 Advanced Operations in Python
24 Python Programming - Operator Precedence
25 Variables in Python
26 Python - Variable Assignment
27 Calculations with Variables
28 Hands-on on Python Variables
29 Types of Variables in Python
30 Python - Calculations with variables
31 Python Programming - Types
32 Guess the Type
33 Python - Guess The Type
34 Operations with Other Types
35 Python - String Concatenation
36 Python - String Operations
37 Conditional Execution and Functions in Python
38 Functions
39 Python - Create Payment Calculator Function
40 Python Programming - Which of the following is not a comparison operator in...
41 Python Programming - Which of the following is used to depict a block...
42 Python Programming - Blank lines are ignored in Python ?...
43 Python Programming - Nested decision statements are possible in Python....
44 Python Programming - The correct syntax for conditional statements in Python is...
45 Python Programming - A try except block in Python is used for...
46 Python Programming - If the try block doesn't raise an exception than the...
47 Python Programming - input(), type(), len() are some of the built in functions...
48 Python Programming - In Python a function is some reusable code that takes...
49 Python Programming - max() and min() are default functions provided in Python for...
50 Python Programming - Executing the code print(max('Hello world')) will result in...
51 Python - Type Conversion
52 Python Programming - Which of the following is not the default data type...
53 Python Programming - Which of the following in-built function in Python is used...
54 Python Programming - Function without any arguments
55 Python Programming - Just defining a function does not execute it, we need...
56 Python Programming - Once we define a function we can call it only...
57 Python Programming - Using in operator
58 Python Programming - We cannot define more than 1 parameter in Python....
59 Built-in Functions
60 Type Conversion Functions
61 Math Functions
62 Random Number Generation
63 Making your own functions
64 Flow of Execution
65 Parameters and Arguments
66 Types of Functions
67 Input from User
68 Comments
69 Boolean Expressions
70 Logical Operators
71 Conditional Execution
72 Visualize the Conditional
73 Catching Exceptions
74 Updating Variables
75 Basic Building Blocks of Python
76 Python Programming - A while loop runs untill the condition provided is true...
77 Python Programming - A break statement ends the current iteration and...
78 Python Programming - Infinite loops are not possible in Python...
79 Python Programming - The statement " for x in [1,2,3,4] : print(x) "...
80 Python Programming - The iteration variable iterates through the sequence...
81 Python Programming - In the statement " for i in [1, 2, 3]...
82 Python Programming - For which of the following application we can use loops?...
83 Python Programming - What are lists
84 Print Even Numbers up to n
85 Compute the Compound Interest
86 While loop
87 Break and Continue
88 For loop
89 Strings
90 String Slices
91 Immutability of Strings
92 in Operator
93 String methods
94 Parsing Strings
95 Format Operator
96 Lists
97 Lists v/s Strings
98 List Methods
99 Deleting Elements of List
100 Lists and Strings
101 Python - Understanding Files
102 Reading Files
103 Searching in Files
104 Writing Files
105 Python Dictionaries and Tuples
106 Python Programming - What are dictionaries
107 Python Programming - Dictionary Keys
108 Python Programming - Dictionary Key Value
109 Python Programming - Dictionary Initialisation
110 Python Programming - Get method in dictionaries
111 Python Programming - Iterating in dictionaries
112 Python Programming - Dictionary Methods
113 Python Programming - Immutable Tuples
114 Python Programming - Tuple Methods
115 Python Programming - Tuple comparison
116 Python Programming - Tuple efficiency
117 Python Programming - Sort and sorted
118 Dictionaries
119 Working with Dictionaries
120 Tuples
121 Working with Tuples
122 Comparison with Tuples
123 Tuple Assignment
124 Tuples and Dictionaries
125 Regular Expressions in Python
126 Network Programming in python
127 HTTP request using Socket
128 Python Classes and Objects
129 Python Programming - Objects
130 Python Programming - dir command on class
131 Python Programming - Class components
132 Python Programming - Purpose of constructors
133 Python Programming - Inheritance
134 Lambda Function and List Comprehension
Loading comments...