You are reading the article List Of The Filters Available In Angularjs With Examples updated in December 2023 on the website Minhminhbmm.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested January 2024 List Of The Filters Available In Angularjs With Examples
Introduction to AngularJS FiltersThe filter is used to filter the elements. In other words filter in angular js is used to filter the element and object and returned the filtered items. Basically filter selects a subset from the array from the original array.
Start Your Free Software Development Course
Web development, programming languages, Software testing & others
Syntax:
comparator: This property is used to determining the value, it compares the expected value from the filtered expression and the actual value from the object array.
anyPropertyKey: This is a special property that is used to match the value against the given property. it has a default value as $.
arrayexpression: It takes the array on which we applied the filter.
expression: It is used to select the items from the array after the filter conditions are met.
Example of AngularJS Filters<script src= {{ x }} </div> angular.module(‘myApp’, []).controller( ‘namesCtrl’, function($scope) { $scope.names = [ ‘xyz’, ‘abc’, ‘uth’, ‘ert’, ‘opu’, ‘wrf’, ‘mkl’, ‘hgt’, ‘mnv’ ]; }); This will show the names contain “m” character filter.
Output:
List of the Filters available in AngularJSAngular js provide many built-in filters which are listed below.
uppercase: This filter is used to format the string to upper case.
lowercase: This filter is used to format the string to lowercase.
currency: This filter is used to format a number to the current format.
orderBy: This filter is used to filter or order an array by an expression.
limitTo: This filter is used to limit the string/array into a specified length or number of elements or characters.
json: This filter is used to format the object to a JSON string.
filter: this filter selects the subset of items from an array.
date: This filter is used to format the date to the specified format.
number: This filter is used to format numbers to a string.
Examples to add filters to expressionLet us how to add filters to expression with the help of examples:
Example #1: UppercaseCode:
angular.module(‘myApp’, []).controller(‘personCtrl’, function($scope) { $scope.firstName = “xyz”, $scope.lastName = “abc” });
Output :
Example #2: LowercaseCode:
angular.module(‘myApp’, []).controller(‘personCtrl’, function($scope) { $scope.firstName = “XYZ”, $scope.lastName = “ABC” });
Output :
Example #3: currency
Code:
var app = angular.module(‘myApp’, []); app.controller(‘currencyCtrl’, function($scope) { $scope.price = 60; });
Output :
Examples to add filters to directivesLet us see how to add filters to directives with the help of examples:
Example #1: orderByangular.module(‘myApp’, []).controller(‘nameandcountryCtrl’, function($scope) { $scope.names = [ {nameEmp:’anil’,countryEmp:’England’}, {nameEmp:’sumit’,countryEmp:’Sweden’}, {nameEmp:’arpita’,countryEmp:’Norway’}, {nameEmp:’pankaj’,countryEmp:’Norway’}, {nameEmp:’joe’,countryEmp:’Denmark’}, {nameEmp:’aman’,countryEmp:’Sweden’}, {nameEmp:’viman’,countryEmp:’Denmark’}, {nameEmp:’manav’,countryEmp:’England’}, {nameEmp:’Kapil’,countryEmp:’Netherland’} ]; $scope.orderByMe = function(x) { $scope.myOrderBy = x; } });
Output :
Example #2: LimtToCode:
<script src= var app = angular.module(‘myApp’, []); app.controller(‘myCtrl’, function($scope) { $scope.string = “”; });
Output:
Example #3: JsonCode:
<script src= var app = angular.module(‘result’, []); app.controller(‘resultCtrl’, function($scope) { $scope.names = { “Aman” : 356, “Vijay” : 908, “Pamkaj” : 645, “Chinmay” : 195, “Joe” : 740 }; });
Output :
Example #4: dateWhen we do not specify the date format it takes the default format as ‘MMM d, yyyy’. Here time zone parameter is optional. takes two parameter format and time zone.
Some predefined date format is as follows:
“medium time”: Equivalent to “h:mm:ss a” (2:35:05 AM)
“short date”: Equivalent to “M/d/yy” (5/7/19)
“medium”: Equivalent to “MMM d, y h:mm: ss a”
“long date”: Equivalent to “MMMM d, y” (May 7, 2023)
“short”: Equivalent to “M/d/yy h: mm a”
“short-time”: Equivalent to “h: mm a” (2:35 AM)
“full date”: Equivalent to “EEEE, MMMM d, y” (Tuesday, May 7, 2023)
“medium date”: Equivalent to “MMM d, y” (May 7, 2023)
Code:
<script src= var app = angular.module(‘gfgApp’, []); app.controller(‘dateCntrl’, function($scope) { $scope.today = new Date(); });
Output :
Example #5: numbercode:
<script src= var app = angular.module(‘gfgApp’, []); app.controller(‘numberCntrl’, function($scope) { $scope.value = 75560.569; });
Output:
Advantages of filters in AngularJsFilters are used to manipulate our data. They provide faster processing and hence enhance the performance as well. Filters are very robust as well.
ConclusionWe can use filters anywhere in our angular application like a directive, expression, controller, etc. We can also create custom filters according to which property we want to sort our data. It also reduces code and makes it more readable and optimizes and by creating custom filters we can maintain them into separate files.
Recommended ArticlesYou're reading List Of The Filters Available In Angularjs With Examples
Working Of The Push() Function In Perl With Examples
Introduction to Perl push
In Perl, the push() function is defined as a function to stack up on the elements or add elements to the existing set of items used in implementing the stack or array of elements for either adding or removing the elements using push and pop functions in Perl. In general, the push() function can be defined as an array or stack function for inserting or adding the set of items or values to another set or array of items where this push function is independent of the type of values passed in the set of elements which means the set of elements can have alphabets, numerical or both alpha-numeric values.
Start Your Free Software Development Course
Working of push() function in Perl with ExamplesIn this article, we will discuss the push() function provided by Perl for inserting or adding a set of elements to the existing stack or array of elements which is mainly used as a stack function along with the pop() function, which does the opposite of push() function which means the pop() removes or deletes the set or list of elements from the stack or array of elements. In Perl language, the push() function is defined as the insertion of items to the array or stack that is passed as an argument to this push() function, and also we need to pass another array to store these added items to the defined array and returns the array with added elements.
Now let us see the syntax and Parameters of the push() function in Perl:
Syntax:
push( arr_name, res_list)Parameters:
arr_name: This parameter is used to specify the array name that is declared at the beginning of the code, which already has elements, and the elements are added to this array.
res_list: This parameter is used to specify the set or list of elements separated by a comma that needs to be added to the array defined, which is the first argument to the push() function.
This push() function returns again a set of elements as a new array having the elements of the previous array along with the added elements to this previous or defined array.
Examples of push() function in PerlNow let us see a simple example of how to demonstrate the push() function in Perl:
Example 1 #!/usr/bin/perl print "Demonstration of push() function in Perl:"; print "n"; print "n"; @arr1 = ('Educba ', 'Google ', 'Opera '); print "The first array is given as follows: "; print "n"; foreach $x (@arr1) { print "$x"; print "n"; } print "n"; @arr2 = (20, 40, 60); print "The second array is given as follows: "; print "n"; foreach $r (@arr2) { print "$r"; print "n"; } print "n"; print "After applying push() function to the given arrays"; print "n"; push(@arr1, 'Explorer ', 'UC '); push(@arr2, (80, 100 )); print "The new array after arr1 is applied with push() is as follows:"; print "n"; foreach $y (@arr1) { print "$y"; print "n"; } print "n"; print "The new array after arr2 is applied with push() is as follows:"; print "n"; foreach $s (@arr2) { print "$s"; print "n"; }Output:
In the above program, we are declaring two different arrays one contains string type, and another contains numeric type values. In the above code, we first print all the elements in the array that is declared at the beginning, and then later, we call the push function. We pass the array such as arr1 and arr2, followed by the elements that need to be added to the previously declared array. Then we are printing the new array that has extra elements ( “Explorer” and “UC to arr1, “80” and “100” to arr2) along with the previous elements in both the arrays arr1 and arr2 now contains the elements that were pushed to the previously declared arrays using push() function such as arr1 and arr2 will now have 5 elements in them as arr1 = (‘Educba’, ‘Google’, ‘Opera’, ‘Explorer’, ‘UC’) and arr2 = (20, 40, 60, 80, 100). The output shows the new array, and the values are printed using the foreach loop.
In the above code, we should note that we have passed arguments to the push() function, but if we do not pass any arguments to the function, it will throw an error saying pass enough arguments to execute the push() function Perl. We can see in the below screenshot of the output of the above code that is modified where “push()” only called instead of any other arguments.
Example 2Code:
#!/usr/bin/perl print "Demonstration of use of push() function in Perl:"; print "n"; print "n"; @arr1 = ('Educba ', 'Google ', 'Opera '); print "The first array is given as follows: "; print "n"; foreach $x (@arr1) { print "$x"; print "n"; } print "n"; @arr2 = (20, 40, 60); print "The second array is given as follows: "; print "n"; foreach $r (@arr2) { print "$r"; print "n"; } print "n"; print "After applying push() function to the given arrays"; print "n"; push(@arr1, 'Explorer ', 'UC '); print "n"; print "After applying push() function directly"; print "n"; push @arr2, (50, 70); print "n"; print @arr2; print "n"; print "Applying push() function for joining or appending two arrays"; print "n"; push(@arr1,@arr2); print @arr1; print "n"; print "n"; print "Applying push() function for adding to array reference"; print "n"; my @arr = qw(Python Perl); my $arr_ref = @arr; push ( @{ $arr_ref }, qw(Java Ruby)); print "@{ $arr_ref }n"; exit 0;Output:
In the above program, we can see we are using the push function directly to add the elements, and we also saw how to push() can be used for joining two arrays, and we also saw how we could add elements to the array reference. The output is as shown in the above screenshot.
ConclusionIn this article, we conclude that Perl’s push() function is used to push the elements to the array elements. In this article, we saw a simple example of how the push() function is used on different types of values. In this, we also saw various use of the push() function in appending of the arrays, and we also saw how to add elements to the array reference.
Recommended ArticlesThis is a guide to Perl push. Here we discuss the Working of the push() function in Perl with Examples and how the push() function is used on different types. You may also have a look at the following articles to learn more –
The Best Hvac Filters Of 2023
We may earn revenue from the products available on this page and participate in affiliate programs. Learn more ›
Written By Timothy Dale
Published Feb 10, 2023 1:00 PM
It’s pretty easy to forget about your HVAC air filter. And that can be a good thing—that means the filter is doing its job properly, and your HVAC system is the better for it. It’s keeping out dust and debris, as well as trapping the pet dander, pollen, and other indoor irritants that would otherwise circulate through the system and possibly affect your health and quality of life. For such a small item in your heating, ventilation, and air conditioning system, the right air filter really stays busy. But every three months or so, it’s time to pull out that filter and replace it with a new one to keep your furnace and air-conditioning running smoothly. This guide will help you find one of the best HVAC filters based on various criteria that help ensure a cleaner, more comfortable home.
How we chose the best HVAC filtersOne quick search and you’ll quickly realize that there are more HVAC air filters in more sizes than anyone could possibly test. To narrow down the options, I considered what might work well for the average homeowner—for instance, I have pets, so I need that pet dander gone, and some in my home have allergies, so pollen is a no-no around here. In addition to pets and allergies, here are some other factors I took into account:
Size: Almost all of the filters tested here were 20 by 25 by 1 inches (also one of the most common sizes in furnace filters). However, the actual dimensions of most filters are usually smaller by a quarter of an inch on each side; this means that the filter might not fit as snugly as necessary in some newer models, which could lead to air whistling and inefficient performance.
MERV rating: An air filter’s minimum efficiency reporting value (MERV) rating measures how effectively the filter stops dust and other contaminants from passing through the filter and into the air stream. Filters with higher MERV ratings trap small particles more effectively than filters with lower MERV ratings. How well does a filter remove the things you need removed from your home’s air? That depends greatly upon where you live. While an air filter with a MERV 8 rating works well just about anywhere, those who live in heavy smog areas might want one rated MERV 11 or higher. Those with immunocompromised family members might choose a MERV 13 filter to remove bacteria and viruses.
Airflow: While a MERV 13 air filter might remove everything, that may also mean that the HVAC unit needs to work harder to pull air through the filter. That can lead to problems with the HVAC over time, such as “short cycling” or shutting off prematurely. A lower MERV rating may be the right choice to ensure proper functioning of your unit.
Annual cost: Most filters come in a pack of at least four, with the idea that you will change it every three months and thus have plenty for a year. But that might not be enough, so sometimes a pack of six is much more efficient and might be cheaper. You may also want to consider one of the best air purifiers for your home.
The best HVAC filters: Reviews & RecommendationsChoosing the right HVAC air filter begins with the question of which size you need. Once you figure that out, you’ll find endless options in that particular size. That’s why we’ve narrowed them down to the following five picks to make it easier, because getting the right component the first time can feel like a breath of fresh air.
Best overall: Aerostar 20x25x1 MERV 13 Pleated Air FilterWhy it made the cut: This efficient and quiet filter provides a high level of filtration at a budget-friendly price.
Specs
Rating: MERV 13
Size: 19.75 x 24.75 x 0.75 inches
Quantity: 6
Pros
Filters out bacteria
Affordable price
Made in the USA
Cons
Might not provide a snug fit
Product packaging might allow allergens in before use
This MERV 13 air filter from Aerostar features a pleated design made of 100% synthetic electrostatic material, which gives it high efficiency while permitting low air resistance, resulting in a quieter air exchange. It filters out microscopic particles that lower MERV-rated filters might miss, such as bacteria, spores, lint, dust mites, viruses, pet dander, and pollen.
Though it’s recommended you change this filter every three months, consider changing it every month during the peak of summer or winter. This product is manufactured in the USA by Filtration Group, which makes multiple filtration products for use in homes and businesses.
Best for pets: Colorfil 20x25x1 MERV 8 Air FilterWhy it made the cut: This color-changing filter helps clear the air in pet-filled homes and alerts you when it’s time to be changed.
Specs
Rating: MERV 8
Dimensions: 19.75 x 24.75 x 0.75 inches
Quantity: 4
Pros
Color-changing technology removes guesswork
Excellent for capturing pet hair and dander
Greater capacity for air filtration than other options
Cons
Might not provide a snug fit
Doesn’t pick up the tiniest dust particles
This unique filter from Colorfil starts a vivid pink but slowly turns orange, then yellow, as it collects pollen, dust, pet dander, and odors. The yellow color signals that the filter is at 25% capacity and will need to be changed soon, but it will continue to work, graying as it approaches the end of its useful life. The entire process can take from two weeks to four months. The more pets in a household, the sooner the filter will fill up and become yellow. This MERV 8 filter is made of synthetic fiber and has a pleated design to trap more allergens.
The air filter technology used in this product was originally developed for NASA to protect astronauts in the atmosphere of a spacecraft. As such, it has five times more capacity for air filtration than the leading commercial activated carbon filters. You can also tidy up with the best vacuums for pet hair.
Best for odors: Flanders 16x16x1 NaturalAire with Baking SodaWhy it made the cut: The fiberglass pleats are infused with baking soda, meaning this MERV 8 filter can pick up odors better than most.
Specs
Rating: MERV 8
Dimensions: 16 x 16 x 1 inches
Quantity: 4
Pros
Baking soda for odor control
V-pleats allow for larger surface area
Precise fit
Cons
Can be easily damaged during shipment
Might inhibit airflow on some systems
With V-pleats that allow for a greater surface area and plenty of infused baking soda, expect this sturdy filter from Flanders to take care of odors in the air while also reducing pollen and other allergens. The wire-mesh backing keeps the filter firm and straight in the unit, and unlike many others, the actual dimensions of this filter match the nominal dimensions, making for a precise fit. The result is a strong filter that stands up to constant use of the HVAC system and needs replacement about every three months.
This filter has a MERV rating of 8, which means it can pick up the most common dust and airborne particles without restricting airflow through a well-maintained HVAC unit. Manufactured in the USA, these filters are built into a frame of recyclable clay-coated molding that resists moisture, making these great for use in high-humidity regions. They can be easily damaged during shipment, so check for any problems promptly when they arrive.
Best for allergies: AIRx Filters Allergy 20x25x1 MERV 11 Pleated Air FilterWhy it made the cut: A MERV rating of 11 is just right for removing typical allergens from the air without restricting airflow.
Specs
Rating: MERV 11
Dimensions: 19.50 x 24.50 x 0.75 inches
Quantity: 6
Pros
Higher MERV rating for better allergen removal
More pleats than most retail air filters
Traps smoke and smog
Cons
Might not provide a snug fit
Might restrict airflow in older units
Those who have serious problems with allergies will appreciate this MERV 11 filter from Airx Filters. This filter has more pleats than most filters available to consumers, which means it grabs more of those annoying allergens, such as pet dander, dust mites, mold spores, pollen, fine dust, lint, smog, and smoke. Made in the USA, this filter has sturdy mesh that keeps it from collapsing in the unit, which can be especially helpful if yours is an older unit that may have trouble with airflow when using a higher-rated MERV filter.
The company is a member of the National Air Filtration Association. This filter meets or exceeds the industry standard for performance set forth by the American Society of Heating, Refrigerating and Air-Conditioning Engineers (ASHRAE).
Best budget: Crisp Filters 20x25x1 MERV 8 Air FilterSpecs
Rating: MERV 8
Dimensions: 19.75 x 24.75 x 0.75 inches
Quantity: 6
Pros
Extensive pleats assure better filtration
Traps particles but doesn’t tax the system
Budget-friendly price
Cons
Doesn’t capture viruses or bacteria
Might not provide a snug fit
This MERV 8 filter from Crisp Filters features more pleats than other residential filters, meaning that it can capture more of the debris and allergens floating through your home at a price point that still easily rivals low-performing brands. Use them for up to three months, but for even better operation, replace them every month.
Expect this filter to remove pollen, dust mites, fine dust, and mold. This filter works well in high-temperature, humid, and moist areas without compromising its performance in removing particles from the air. Simple instructions on the filter itself make changing it a breeze. This product is also made in the USA.
Things to consider before buying an HVAC filter Your prioritiesStart by determining your priority—do you want to clean your home’s air of dust and other allergens, are you concerned about your city’s smog level, or do you want a filter that can help with odors as well as particulate matter? Once you know your expectations for the filter, you can choose options by looking at the MERV ratings. The MERV is typically printed very clearly on the filter, but some filters might use different rating systems. The MPR, or Microparticle Performance Rating, is favored by 3M for their filters, while Home Depot uses the FPR, or Filter Performance Rating, for filters that carry the Home Depot name. What they all have in common is that the higher the number, the better the filtration.
But with higher filtration may come the downside of reduced airflow. To capture the tiniest viruses and bacteria, the material that catches those particles must be of a very tight weave. Some older units may have trouble moving air through the material. Consider the difference between trying to breathe through a piece of cheesecloth versus a piece of terry cloth; the cheesecloth doesn’t restrict breathing at all, but the terry cloth certainly does. When you try out a filter, ensure it’s not blocking too much air, or the filtration will be negated by the lack of air moving around the house.
SizeFilters come in many different sizes to fit various HVAC systems. Check carefully the measurements needed for your system to ensure proper fit. Most filters, like the ones reviewed here, are one inch thick, but some systems may require one with a thickness of up to five inches. Remember, again, the more filter the air has to go through, the tougher it gets for the unit to run properly.
FAQs Q: Are HVAC air filters reusable?Some HVAC air filters are reusable. While most filters are the disposable type, some units accept reusable filters that can be cleaned with warm water and dried before using them again.
Q: Does where I live make a difference in my filter?Yes, where you live makes a big difference when selecting the best HVAC filter. For instance, those who live in very humid or damp areas will want a MERV rating of 6 or higher to capture mold spores, while those who live in urban areas with a great deal of smog might want a filter with a rating of MERV 11 or higher.
Q: Why is my air filter whistling?The sound of your air filter whistling might result from air flowing around the filter rather than through it. The air flowing around it means the filter isn’t fitting snugly and therefore is not working efficiently. Measure carefully and choose a filter that fits the space. Pay attention to the actual size, not the nominal size.
Final thoughts on the best HVAC filtersIt’s a fine balance between a filter that cleans effectively and doesn’t impede airflow. Look for a filter that removes as much as possible without leading to air restriction. Many newer model HVAC systems can easily handle MERV 11 or higher, such as our best overall pick, the Aerostar 20x25x1 MERV 13 Pleated Air Filter.
Working Of Import Directory In Sass With Examples
Introduction to SASS Import
SASS stands for Syntactically Awesome Style Sheet which is a css pre-processor that provides a feature to your stylesheet mark-up to make the writing styles in different ways.
Start Your Free Software Development Course
Web development, programming languages, Software testing & others
The @import is a directive in SASS pre-processor which is used to keep associated code in separate files. It allows us to continue code in one file as opposed to keeping the same code over numerous files. The @import directive can be used to import SCSS files in our main file, therefore essentially, we can combine multiple files together.
The .css will be the extension for a file
The url() can be a filename
The media queries can be used using @import directive
SyntaxThe syntax for @import directive in SASS can be written as shown below:
Syntax:
@import mystyle.sass;The above line includes the style sheet into another style sheet by using the @import directive. For instance, let’s take a file as chúng tôi with the below code:
Code:
a { color: blue; } body { font-size: 15px; background-color: red; }Now, create another file with the name chúng tôi along with the below code:
Code:
@import "demo.scss"; p { color: green; font-weight: 200; }When you compile the code, you will get the below code with the combination of above both files:
Code: demo2.css
a { color: blue; } body { font-size: 15px; background-color: red; } p { color: green; font-weight: 200; } Working of Import Directory in SASS
The import directive enables us to add several styles and can be broken into separate files to import them into one another. In this way, the SASS import directive works speedily to edit the style sheet.
Different plain CSS imports need the browser to make multiple HTTP requests as it displays your web page, and during the compilation time, Sass imports are handled entirely.
SASS works on the @import CSS. It does not involve an HTTP request. Instead, it usually takes the file we want to import and integrates it with the file you are importing into, so you can represent the web browser with a single CSS file.
Examples to Implement SASS Import DirectoryBelow are the examples:
Example #1To run SASS files, you need to install Ruby for executing SASS programs. Create a file with name sass_import.html with the below code:
Code: sass_import.html
Educba is online teaching providing server which helps various stream people or candidates to upgrade their knowledge respective to their domain.
Now create an scss file with name import_demo.scss and put the below code.
Code: import_demo.scss
html, body { margin: 0; padding: 0; } .styledemo { font-size:25px; background-color: green; }Put the above both two files in the root folder of the installed ruby folder. Now open the command prompt and run the below command to watch the file and communicates it to SASS and updates the CSS file every time SASS file changes.
Code:
sass --watch import_demo.scss: import_demo.cssThe above command will create a CSS file and called import_demo.css in the same folder where Ruby is installed. The import_demo.css file includes the below code.
Code:
html, body { margin: 0; padding: 0; } .styledemo { font-size: 25px; background-color: green; }Output: Now, execute the html file and open in the browser and you will get the below result:
Example #2In this example, we have used @import directive which imports the content of one file into another file. Let’s create a html file and save the below code as import_demo_example.html.
Code:
Now create a file called sass_import.scss with the below code:
Code:
ul{ margin: 0; padding: 1; } li{ color: #82BBDB; }Code:
@import "sass_import"; .block { background: #26688D; } h2 { color: #B98D25; }Explanation: In the above file, we are importing a sass-import file which adds its content into in this file when you made changes to the scss file. The @import could include the style sheet inside the other style sheets. The comprised files could either be placed on a similar server or added with a URL to a directory on the alternative server.
Now open the command prompt and run the below command to watch the file and communicates it to SASS and updates the CSS file every time SASS file changes.
Code:
sass –watch sass_import_demo.scss: sass_import_demo.cssNow, execute the file with the above command and it will create the sass_import_demo.css file with the below code:
Code: sass_import_demo.css
ul { margin: 0; padding: 1; } li { color: #82BBDB; } .block { background: #26688D; } h2 { color: #B98D25; }Output: Now, execute the html file and open in the browser and you will get the below result.
Benefit of SASS ImportThe main benefit of using the @import directive is, we can merge several files using @import and then compile the main file. Therefore, as a result, we will have only one CSS file and hence, the browser will not have to create more than one HTTP request to load up separate CSS files.
ConclusionThe @import Sass directive is one of the CSS rules which can help to maintain the code and break down the larger files into tiny files and also, facilitates import other files and ultimately one top-level file that will be compiled into CSS. If you are utilizing Sass pre-processor, you will create a good structure for your stylesheets. The structure without @import directive in Sass pre-processor is not possible to do properly.
Recommended ArticlesThis is a guide to SASS Import. Here we discuss syntax to SASS Import, working off and examples to implement with knowing its benefits. You can also go through our other related articles to learn more –
Working Of Mkdir In Python With Programming Examples
Introduction to Python mkdir
In this article, we will explore the Python mkdir function, which serves the purpose of creating new directories. The mkdir command is a feature available in various scripting languages such as PHP and Unix. However, in older versions like DOS and OS/2, the mkdir command has been replaced with md. In Python, we can utilize the mkdir method, which is provided by the OS module for seamless interaction with operating systems. To create directories in Python, we employ the os.mkdir() method, specifying the numeric mode and path as arguments.
Start Your Free Software Development Course
Web development, programming languages, Software testing & others
Working of mkdir in Python with ExamplesSyntax of mkdir() function:
os.mkdir(path, mode =0o777, *, dir_fd = none)Parameters:
The “path” parameter is used in the os.mkdir() function to specify the file system path for the directory to be created. It can be either a string or bytes object that represents a path-like object.
The “mode” parameter is optional and is represented as an integer value. It determines the file permissions for the newly created directory. If this parameter is not specified, it defaults to a value of 0o777.
The “*” symbol indicates that the following parameters are keyword-only parameters, meaning they can only be specified using their names.
The “dir_fd” parameter is also optional and represents a file descriptor referring to the directory. Its default value is None.
This function os.mkdir() returns nothing, which means it cannot return any value.
Example #1Example of mkdir() function.
Code:
import os os.mkdir('sample') print('The directory is created.')Output:
In the above program, we can see a simple code for creating a directory using mkdir() function of the OS module in Python.
Example #2Now let us see in detail how to create a directory with specifying path and mode while creating the directory. We will also see how to cross-check the creation of directories in the command prompt. Let us see the below example of the creation of directories.
Code:
import os print("Python program to explain os.mkdir() method") print("n") print("The directory name is given as:") dir_name = "Educba" print(dir_name) print("n") print("The path to create directory specified is as follows:") pa_dir = "D:/" print("n") path = os.path.join(pa_dir, dir_name) print("n") print("The mode is also specified as follows:") mode = 0o666 print(mode) print("n") os.mkdir(path, mode) print("Directory has been '%s' created" %dir_name) print("n")In the above program, we can see we are creating directories, one specifying the path and another directory specifying the mode. In the above screenshot of output, we can see both program and output of the program ad to confirm whether the directories are created; we can see it in the command prompt along with the date and time of creation.
Example #3In Python, this mkdir() function, when used, might raise an error known as FileExistsError.
For the above program, if we try to execute it once again or if we are trying to create a directory that is already present in the drive, then it will give an error, and it can be shown as the below output.
Output:
Example #4Now let us demonstrate how to declare or use the Python makedirs() method along with syntax and the example below.
Syntax:
makedirs(path [,mode])
path: This is used to specify the path to which the directory is created recursively.
mode: This parameter is given to the directories to specify the mode of file permissions.
This function also will not return any value as the function mkdir() also does not return any value.
Code:
import os print("Python program to explain os.mkdir() method") print("n") dir_name = "Article" print(dir_name) print("n") dir_path = "D:/" path = os.path.join(dir_path, dir_name) os.makedirs(path) print("Directory has been created using makedirs() '%s' created" %dir_name) print("n")Output:
ConclusionThis article concludes that the mkdir() function uses the OS module to create directories in Python. The article also provides an example and syntax demonstrating the usage of this function. In this article, we also saw another function similar to mkdir() function for creating a recursive directory using makedirs().
Recommended Articles
This is a guide to Python mkdir. Here we discuss the introduction to Python mkdir and the working of mkdir with programming examples. You may also have a look at the following articles to learn more –
Learn The Implementation Of Db2 Cast With Examples
Introduction to DB2 CAST
DB2 CAST is a function available in DB2 that is used for explicit conversion of the data type of a particular value to another datatype. DB2 comes with the default facility of trying to convert the datatypes of the values if they are not mentioned properly to an expected data type value in all the functions and the instructions that are issued and where there is a necessity of doing so. This is called implicit casting or conversion of a datatype. In this article, we will study how we can convert the value of one data type to another with the help of the CAST() function available in DB2, the syntax of the CAST() function, and the implementation with the help of certain examples.
Start Your Free Data Science Course
Hadoop, Data Science, Statistics & others
Syntax
CAST(any expression or value AS the required datatype)
In the above expression, the expression or value can be any field value of a particular table column or a constant value, or even a variable that holds a certain value. The required data type is the data type that you want the value mentioned as the expression to be converted to. We can specify any data type, we want the data to convert to such as int, string, etc.
Implicit casting in DB2 ExamplesConsider the following example where we are trying to add 6 integer value with ‘16’ string value using the plus(+) operator and retrieve the result –
6 + ’16’ as result ;
The execution of the above query statement gives the following output with the resultant value being an integer which is 22. Over here, DB2 firstly converted the string ‘16’ to an integer value and then went for doing the addition.
Let us consider one more example where we will be using the concatenation operator which is a string operator and works only with string. When we use the same values specified in the above example 6 and ‘16’ which are an integer and a string, using the following query statement –
The execution of the above query statement gives the following output with the resultant value being a string which is 616. Over here, DB2 firstly converted the integer 6 to string value and then goes for doing the concatenation.
Now, let us see, how we can cast the values explicitly using the CAST() function. If the values cannot be cast by the DB2 due to incompatible type of values, it throws an error saying as shown in the below image –
Now, let us try to convert a decimal value to an integer value using the DB2 CAST() function which will do explicit datatype conversion for us. Consider the following query statement where we are trying to convert a decimal number 14.562 to and integer value to get a rounded whole number. We can do this by using the following query statement with the CAST() function in it –
The output of the above query statement is a rounded integer value of 14.562 which is 14 as shown below –
Now, consider a decimal number 16.5454 which we want to cast to a decimal number itself but a lower scale value to it. We can even do this by using the CAST() function and our query statement, in this case, will look as follows –
CAST ( 16.5454 DEC (4,2)) AS result;
The output of the above query statement’s execution is as shown below with the number rounded and cast to a decimal value of two places after a decimal point has a different scale than the original one –
Let us try to convert a value of the TIMESTAMP datatype to the TIME datatype, in order to get only the time value in the output. We will convert the current timestamp value to time using the cast function in the following query statement to retrieve the current time value of the system –
CAST (CURRENT TIMESTAMP AS TIME) as result;
The execution of the above query statement gives the following result where we get the value of the current time of the system from the current TIMESTAMP value which is as shown below –
We can even convert the current timestamp value to the date datatype in order to retrieve today’s date of my system and using the following query statement and the CAST() function –
CAST (CURRENT TIMESTAMP AS DATE) as result;
The output of the execution of the above query statement is as shown below with the date value in it which is the current system date.
Let us try one last example where we will cast the value of string data type to a DATE datatype explicitly by using the CAST() function in DB2 RDBMS. Let us consider a random date value say ‘2030-01-27’. We will try to convert this string to DATE datatype by using the following query statement –
CAST(‘2030-01-27’ AS DATE) result;
The output of the execution of the above query statement in DB2 DBMS gives the following resultant value with the date specified being cast to a DATE data type as shown below –
ConclusionIN DB2 RDBMS, the datatypes are internally converted into required datatypes while using the functions and manipulations and while doing operations. However, if we want to explicitly convert a particular value to a required datatype then we can make use of the CAST() function to convert the value to a different datatype explicitly in DB2 RDBMS. We can convert the data type f the values to any in-built and user-defined datatype using the CAST() function.
Recommended ArticlesThis is a guide to DB2 CAST. Here we discuss how we can convert the value of one data type to another with the help of the CAST() function. You may also look at the following article to learn more –
Update the detailed information about List Of The Filters Available In Angularjs With Examples on the Minhminhbmm.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!